Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all 3021 articles
Browse latest View live

Using ifstream, string stream, and extraction operator >>

$
0
0
Let's say I have a file that is entirely strings but it's binary due to some nulls ('\0') in between the strings. So technically, it's not an ascii file (32 - 128), it's got some 0's in it. So using, cat, it would be cat -A thefile.txt to see that there are nulls in it. cat thefile.txt would just show the pure ascii text. I can create an ifstream object and read it in line by line using either of the following: #include (the proper include files, sorry I've omitted them here) using namespace std; string buffer; ifstream if; getline(if, buffer, '\n'); or getline(if, buffer); or: if >> buffer; The above 3 different methods will ALL read an entire line from the file. I can easily prove this by cout << "buffer = " << buffer; and it will display the line from the file, including any nulls or whatever. But now suppose, I want to use extraction (as in I want to tokenize the lines into parsed strings, right into string variables). My problem is that stringstream does NOT behave in this manner unless you have a true mixture of binary globs of data. As soon as you stringstream extract into a string variable, it reverts right back to the behavior of the getline and grabs the entire line. Is there anyway I can use extraction and have it understand that I want ONE string at a time? For example, by setting a delimiter? I know I can set a delimiter in the getline function. It's just that I want to do it with the extraction operator (ie. modify stringstream and/or ifstream's extraction). Or is there yet another class that I'm missing? I do not want to use boost in this project. And I do not want only Windows-specific classes - I want something generic. If I really do have to "roll my own", then fine, I have to do that. In my case, if I DO have to roll a new extraction or overload the behavior, it will need to be done for all types, not just strings - I would guess. Thanks.

Data Received From Serial Port not

$
0
0
hi all i am received following string from Device and store in database N1Z1802200000000000001000000S009000570101640048500851202880033800265003140015000536000280001400048004420013100098002530 Problem is date 1.) complete data not show in Text box 2.) Data save in database in shape of multi record . Kindly advise me . ===code Start ======= using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO.Ports; using System.Data.OleDb; using MY251_Final.Screens.Templates; using System.Configuration; namespace M235_Final { public partial class TestingUtilityForm : TemplateForm { OleDbConnection connection = new OleDbConnection(); // String DataOut; String DataIN; public TestingUtilityForm() { InitializeComponent(); connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\Interfacing.accdb"; } private void TestingUtilityForm_Load(object sender, EventArgs e) { connection.Open(); connectionStatusLabel.Text = "Connection Establish"; connection.Close(); // Create Function to get Serial Port string[] ports = SerialPort.GetPortNames(); comPortsComboBox.Items.AddRange(ports); } private void openButton_Click(object sender, EventArgs e) { try { serialPort1.PortName = comPortsComboBox.Text; serialPort1.BaudRate = Convert.ToInt32(baudComboBox.Text); serialPort1.DataBits = Convert.ToInt32(dataBitsComboBox.Text); serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), stopBitsComboBox.Text); serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), parityComboBox.Text); serialPort1.Open(); progressBar1.Value = 100; } catch (Exception Err) { MessageBox.Show(Err.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void closeButton_Click(object sender, EventArgs e) { if (serialPort1.IsOpen) { serialPort1.Close(); progressBar1.Value = 0; } } private void sendDataButton_Click(object sender, EventArgs e) { } private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) { DataIN = serialPort1.ReadExisting(); this.Invoke(new EventHandler(ShowData)); try { connection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connection; command.CommandText = "insert into tblData(MYdata) values('"+ DataIN + "')"; command.ExecuteNonQuery(); DataIN = null; connection.Close(); } catch (Exception ex) { MessageBox.Show("error"+ex); } } private void ShowData(object sender, EventArgs e) { int dataINLength = DataIN.Length; dataInLengthLabel.Text = String.Format("{0:00}", DataIN.Length); INdataTextBox.Clear(); INdataTextBox.Text += DataIN; } private void portStatusLabel_Click(object sender, EventArgs e) { } private void clearButton_Click(object sender, EventArgs e) { INdataTextBox.Text = ""; dataInLengthLabel.Text = ""; } private void INdataTextBox_TextChanged(object sender, EventArgs e) { int DataOutLength = INdataTextBox.TextLength; dataInLengthLabel.Text = String.Format("{0:00}", DataOutLength); } private void connectionStatusLabel_Click(object sender, EventArgs e) { } private void showDataButton_Click(object sender, EventArgs e) { try { connection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connection; string query = "select * from tblData"; command.CommandText = query; OleDbDataAdapter da = new OleDbDataAdapter(command); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; connection.Close(); } catch (Exception ex) { MessageBox.Show("error" + ex); } } } } =======End Code============== Attachment 35177 (http://forums.codeguru.com/attachment.php?attachmentid=35177)

microsoft spy does not detect any message with an application

$
0
0
-hi, i have an application and if I use microsoft spy to see the messages to the window of an application, it doesn't detect anything.
I'm asking, how is it possible?neither the mouse or nothing...thank you. does Spy detect messages also if the application is written in Java?

C++ program.

$
0
0
I want to realize program in c ++ in order to choose the best point by using several caracteristics. Each point vas its own caracteristics. Need help

Close [X] aplication issue

$
0
0
Hi!! I have a MDI aplication that has MDI windows and top windows and unfortunately the document interface is not implemented. When I press the X button on the aplication (not on the child frame) I need to save all modified documents on MDI and on Top Windows, but before save the documents and close the window I need to get the name of the file that is on the view. The problem is that I cant get acess the all views from the childframe. In OnClose on the MainFrame I made a while to acess all views and get the file name but it is not working. I have tried get the view form several messages like GetActiveView() GetWindow() and send message (WM_SETFOCUS) from all possible ways. (If I get the focus on the view I can get the filename.) nothing is working. What is Wrong? I wrote on Onclose of the MainFrame: Code: --------- void CMainFrame::OnClose() { int Maximized(0); CMDIChildWnd *CW(MDIGetActive(&Maximized)),*PrimCW(CW); while(CW) { //--- none of these is working.... ---------------------------------------- CW->GetDesktopWindow()->SetFocus(); CW->GetDesktopWindow()->SendMessage(WM_SETFOCUS); CW->GetWindow(WM_SETFOCUS); ///-------------------------------------------------------------------------- CW->SendMessage(WM_CLOSE); //--- Ok but I don´t get the file name. MDINext(); CW = MDIGetActive(&Maximized); if(CW == PrimCW) CW = NULL; } CMDIFrameWnd::OnClose(); } --------- Thank you

Using PsSetCreateProcessNotifyRoutineEx

$
0
0
I am trying to see when a new process is loaded into memory, and, for that I am intend to use PsSetCreateProcessNotifyRoutineEx method. In MSDN documentation say that this method has need Code: --------- #include "Ntddk.h" --------- Ok, for that, I have installed WinDDK in C:\WinDDK\7600.16385.1\, and I set additional include directory: C:\WinDDK\7600.16385.1\inc\ddk\ but soon after I set this, I got the following errors: Code: --------- 1>Compiling... 1>stdafx.cpp 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(60) : error C2065: '_In_opt_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(60) : error C2146: syntax error : missing ')' before identifier 'new_handler' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(60) : warning C4229: anachronism used : modifiers on data are ignored 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(60) : error C2491: 'std::set_new_handler' : definition of dllimport data not allowed 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(60) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(85) : error C2065: '_Size' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(85) : error C2448: '_Ret_opt_bytecap_' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(86) : error C2065: '_Size' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(86) : error C2448: '_Ret_opt_bytecap_' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(107) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(107) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(107) : error C2448: '_set_new_mode' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(107) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(118) : error C2143: syntax error : missing ';' before '__cdecl' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(119) : error C2143: syntax error : missing ';' before '__cdecl' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(119) : error C2065: '_In_opt_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(119) : error C2146: syntax error : missing ')' before identifier '_PNH' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(119) : warning C4229: anachronism used : modifiers on data are ignored 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(119) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(119) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\excpt.h(59) : error C2143: syntax error : missing ';' before '__cdecl' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\excpt.h(60) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\excpt.h(60) : error C2144: syntax error : '_EXCEPTION_RECORD' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\excpt.h(60) : error C2448: '_except_handler' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\excpt.h(61) : error C2144: syntax error : 'void' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\excpt.h(62) : error C2144: syntax error : '_CONTEXT' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\excpt.h(63) : error C2144: syntax error : 'void' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\excpt.h(64) : error C2059: syntax error : ')' 1>c:\winddk\7600.16385.1\inc\api\windef.h(49) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(51) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(53) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(157) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(158) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(159) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(160) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(161) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(164) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(165) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(167) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\7600.16385.1\inc\api\windef.h(168) : error C2143: syntax error : missing ';' before '*' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(94) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(94) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(94) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(94) : error C2448: '_isctype' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(94) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(94) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(95) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(95) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(95) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(95) : error C2448: '_isctype_l' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(95) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(95) : error C2146: syntax error : missing ';' before identifier '_locale_t' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(95) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(96) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(96) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(96) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(96) : error C2448: 'isalpha' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(96) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(97) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(97) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(97) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(97) : error C2448: '_isalpha_l' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(97) : error C2146: syntax error : missing ';' before identifier '_locale_t' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(97) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(98) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(98) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(98) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(98) : error C2448: 'isupper' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(98) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(99) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(99) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(99) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(99) : error C2448: '_isupper_l' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(99) : error C2146: syntax error : missing ';' before identifier '_locale_t' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(99) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(100) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(100) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(100) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(100) : error C2448: 'islower' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(100) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(101) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(101) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(101) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(101) : error C2448: '_islower_l' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(101) : error C2146: syntax error : missing ';' before identifier '_locale_t' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(101) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(102) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(102) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(102) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(102) : error C2448: 'isdigit' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(102) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(103) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(103) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(103) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(103) : error C2448: '_isdigit_l' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(103) : error C2146: syntax error : missing ';' before identifier '_locale_t' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(103) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(104) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(104) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(104) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(104) : error C2448: 'isxdigit' : function-style initializer appears to be a function definition 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(104) : error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(105) : error C2144: syntax error : 'int' should be preceded by ';' 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(105) : error C2065: '_In_' : undeclared identifier 1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\ctype.h(105) : fatal error C1003: error count exceeds 100; stopping compilation --------- what could be the problem ? Could you help me ? Thank you.

riched20 in 64 bit app

$
0
0
I.m using a control CRichText in a dialog. My App was in 32 bit platform and i use riched20.dll for this. When i upgrade the App from Visual Studio 2008 to Visual Studio 2017 and compile for a 64 bit platform, the App fails when i create this dialog. Can someone help me? Perhaps i need another dll or is there any other problem. Thanks you PERE

How to create a AutoHotkey like hotstring using C++?

$
0
0
I have figured out an effective way to create a hotkey using C++. AutoHotkey example Alt+A to run a file. Alt & a:: Run, C:\blah\blah\blah\abc.png Return C++ example Alt+A to run a file. Code: --------- while(true) { if( GetKeyState(VK_MENU) & 0x8000 ) { if( GetKeyState('A') & 0x8000 ) { ShellExecute(NULL, "open", "C:\\blah\\blah\\blah\\abc.png", NULL, NULL, SW_SHOWNORMAL); }}} --------- I now want to understand how to create a hotstring using C++. For example how can I convert following AutoHotkey code into C++? Code: --------- ::abc:: Run, C:\blah\blah\blah\abc.png Return --------- I don't know what logic the AutoHotkey developers used in creating the hotstring functionality but I think something like this might work. Code: --------- if( GetKeyState(VK_SPACE) & 0x8000 ) { // press Shift+Left until space detected; // press Shift+Right after space detected; // press Control+C to send highlighted word clipboard; // convert clipboard to string; // add that string to a variable; if(//the value of variable is abc) { ShellExecute(NULL, "open", "C:\\blah\\blah\\blah\\abc.png", NULL, NULL, SW_SHOWNORMAL); } else {//send space}} --------- The problem is I don't know how to implement this completely because while I can send keyboard events, I don't know how to detect highlighted characters and use them in if statements. plus, I don't know if this is the best way because it might make typing a simple space take too long. Someone please help.

CView to PDF

$
0
0
I have an MDI app, with view derived from CScrollView, where I draw text, lines, and images. Is there any chance to export this CMyView to PDF, without any virtual printer or some third part library ? Of course that I have search on internet for solution, but I have found nothing ... Can you guide me to solve this issue ? Thank you.

Matlab

$
0
0
Name:  MATlab.jpg
Views: 12
Size:  42.2 KB
I have a Gui with a table in it.
When a press a button it should fill the able with the results from an array in the workspace!


BatteryDischargeCalc = assign(handles.uitable5,'data')


% set(handles.uitable10, 'Data', BatteryDischargeCalc);

These are the commands I have tried and have had no luck?
Any ideas?
Attached Images
 

[RESOLVED] Matlab

$
0
0
Attachment 35183 (http://forums.codeguru.com/attachment.php?attachmentid=35183) I have a Gui with a table in it. When a press a button it should fill the able with the results from an array in the workspace! BatteryDischargeCalc = assign(handles.uitable5,'data') % set(handles.uitable10, 'Data', BatteryDischargeCalc); These are the commands I have tried and have had no luck? Any ideas?

[RESOLVED] Fail to inject image of dll file in remote process

$
0
0
I want inject and execute the image of a x32 dll file in a remote x32 process (manual map injection) and to make this i found this following code, but he have a error in a line present in *FixImports()* method :(: Code: --------- if(!GetRemoteModuleHandle(pId, module)) { retfix=0; break; }; --------- Attachment 35189 (http://forums.codeguru.com/attachment.php?attachmentid=35189) How fix it? Complete code: Code: --------- // Mapping.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "resource.h" #include #include #include #include #include using namespace std; #pragma comment(lib, "shlwapi.lib") #define ID_LOADER_DLL MAKEINTRESOURCE(IDR_DLL1) #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 #define MakePtr( cast, ptr, addValue ) (cast)( (DWORD_PTR)(ptr) + (DWORD_PTR)(addValue)) #define MakeDelta(cast, x, y) (cast) ( (DWORD_PTR)(x) - (DWORD_PTR)(y)) HMODULE GetRemoteModuleHandle(unsigned long, char *); FARPROC GetRemoteProcAddress(unsigned long, char *, char *); bool FixImports(unsigned long, void *, IMAGE_NT_HEADERS *, IMAGE_IMPORT_DESCRIPTOR *); bool FixRelocs(void *, void *, IMAGE_NT_HEADERS *, IMAGE_BASE_RELOCATION *, unsigned int); bool MapSections(HANDLE, void *, void *, IMAGE_NT_HEADERS *); PIMAGE_SECTION_HEADER GetEnclosingSectionHeader(DWORD, PIMAGE_NT_HEADERS); LPVOID GetPtrFromRVA(DWORD, PIMAGE_NT_HEADERS, PBYTE); __declspec(naked) void DllCall_stub(HMODULE hMod) { _asm { push 0 push 1 push [esp+0Ch] mov eax, 0xDEADBEEF call eax ret } } __declspec(naked) void DC_stubend(void) { } bool MapRemoteModule(unsigned long pId, /*LPCSTR ResName*/char *module) { IMAGE_DOS_HEADER *dosHd; IMAGE_NT_HEADERS *ntHd; /* HMODULE hModule = GetModuleHandle(NULL); HRSRC hResource = FindResource(hModule, ResName, RT_RCDATA); HGLOBAL hMemory = LoadResource(hModule, hResource); DWORD dwSize = SizeofResource(hModule, hResource); LPVOID lpAddress = LockResource(hMemory); unsigned char *dllBin = new unsigned char[dwSize]; memcpy(dllBin, lpAddress, dwSize); unsigned int nBytes = dwSize; */ HANDLE hFile = CreateFile(module, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return false; unsigned int fSize; if (GetFileAttributes(module) & FILE_ATTRIBUTE_COMPRESSED) fSize = GetCompressedFileSize(module, NULL); else fSize = GetFileSize(hFile, NULL); unsigned char *dllBin = new unsigned char[fSize]; unsigned int nBytes; ReadFile(hFile, dllBin, fSize, (LPDWORD)&nBytes, FALSE); CloseHandle(hFile); dosHd = MakePtr(IMAGE_DOS_HEADER *, dllBin, 0); if(dosHd->e_magic != IMAGE_DOS_SIGNATURE) { delete dllBin; return false; } ntHd = MakePtr(IMAGE_NT_HEADERS *, dllBin, dosHd->e_lfanew); if(ntHd->Signature != IMAGE_NT_SIGNATURE) { delete dllBin; return false; } HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId); if(!hProcess) return false; void *moduleBase = VirtualAllocEx(hProcess, NULL, ntHd->OptionalHeader.SizeOfImage, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if(!moduleBase) return false; void *stubBase = VirtualAllocEx(hProcess, NULL, MakeDelta(SIZE_T, DC_stubend, DllCall_stub), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if(!stubBase) return false; IMAGE_IMPORT_DESCRIPTOR *impDesc = (IMAGE_IMPORT_DESCRIPTOR *)GetPtrFromRVA( (DWORD)(ntHd->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress), ntHd, (PBYTE)dllBin); if(ntHd->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size) { if(!FixImports(pId, (unsigned char *)dllBin, ntHd, impDesc)) return FALSE; }; IMAGE_BASE_RELOCATION *reloc = (IMAGE_BASE_RELOCATION *)GetPtrFromRVA( (DWORD)(ntHd->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress), ntHd, (PBYTE)dllBin); if(ntHd->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size) { FixRelocs(dllBin, moduleBase, ntHd, reloc, ntHd->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size); } else { return false; }; WriteProcessMemory(hProcess, moduleBase, dllBin, ntHd->FileHeader.SizeOfOptionalHeader + sizeof(ntHd->FileHeader) + sizeof(ntHd->Signature), (SIZE_T *)&nBytes); MapSections(hProcess, moduleBase, dllBin, ntHd); VirtualProtect((LPVOID)DllCall_stub, MakeDelta(SIZE_T, DC_stubend, DllCall_stub), PAGE_EXECUTE_READWRITE, (DWORD *)&nBytes); *MakePtr(unsigned long *, DllCall_stub, 9) = MakePtr(unsigned long, moduleBase, ntHd->OptionalHeader.AddressOfEntryPoint); WriteProcessMemory(hProcess, stubBase, (LPVOID)DllCall_stub, MakeDelta(SIZE_T, DC_stubend, DllCall_stub), (SIZE_T *)&nBytes); CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)stubBase, moduleBase, 0, NULL); delete dllBin; return true; } bool MapSections(HANDLE hProcess, void *moduleBase, void *dllBin, IMAGE_NT_HEADERS *ntHd) { IMAGE_SECTION_HEADER *header = IMAGE_FIRST_SECTION(ntHd); unsigned int nBytes = 0; unsigned int virtualSize = 0; unsigned int n = 0; for(unsigned int i = 0; ntHd->FileHeader.NumberOfSections; i++) { if(nBytes >= ntHd->OptionalHeader.SizeOfImage) break; WriteProcessMemory(hProcess, MakePtr(LPVOID, moduleBase, header->VirtualAddress), MakePtr(LPCVOID, dllBin, header->PointerToRawData), header->SizeOfRawData, (LPDWORD)&n); virtualSize = header->VirtualAddress; header++; virtualSize = header->VirtualAddress - virtualSize; nBytes += virtualSize; VirtualProtectEx(hProcess, MakePtr(LPVOID, moduleBase, header->VirtualAddress), virtualSize, header->Characteristics & 0x00FFFFFF, NULL); } return true; } bool FixImports(unsigned long pId, void *base, IMAGE_NT_HEADERS *ntHd, IMAGE_IMPORT_DESCRIPTOR *impDesc) { char *module; bool retfix=1; char tempstr[MAX_PATH]=""; while((module = (char *)GetPtrFromRVA((DWORD)(impDesc->Name), ntHd, (PBYTE)base))) { if(!GetRemoteModuleHandle(pId, module)) { retfix=0; break; }; IMAGE_THUNK_DATA *itd = (IMAGE_THUNK_DATA *)GetPtrFromRVA((DWORD)(impDesc->FirstThunk), ntHd, (PBYTE)base); while(itd->u1.AddressOfData) { IMAGE_IMPORT_BY_NAME *iibn; iibn = (IMAGE_IMPORT_BY_NAME *)GetPtrFromRVA((DWORD)(itd->u1.AddressOfData), ntHd, (PBYTE)base); itd->u1.Function = MakePtr(DWORD, GetRemoteProcAddress(pId, module, (char *)iibn->Name), 0); itd++; } impDesc++; } return retfix; } bool FixRelocs(void *base, void *rBase, IMAGE_NT_HEADERS *ntHd, IMAGE_BASE_RELOCATION *reloc, unsigned int size) { unsigned long ImageBase = ntHd->OptionalHeader.ImageBase; unsigned int nBytes = 0; unsigned long delta = MakeDelta(unsigned long, rBase, ImageBase); while(1) { unsigned long *locBase = (unsigned long *)GetPtrFromRVA((DWORD)(reloc->VirtualAddress), ntHd, (PBYTE)base); unsigned int numRelocs = (reloc->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD); if(nBytes >= size) break; unsigned short *locData = MakePtr(unsigned short *, reloc, sizeof(IMAGE_BASE_RELOCATION)); for(unsigned int i = 0; i < numRelocs; i++) { if(((*locData >> 12) & IMAGE_REL_BASED_HIGHLOW)) *MakePtr(unsigned long *, locBase, (*locData & 0x0FFF)) += delta; locData++; } nBytes += reloc->SizeOfBlock; reloc = (IMAGE_BASE_RELOCATION *)locData; } return true; } FARPROC GetRemoteProcAddress(unsigned long pId, char *module, char *func) { HMODULE remoteMod = GetRemoteModuleHandle(pId, module); HMODULE localMod = GetModuleHandle(module); unsigned long delta = MakeDelta(unsigned long, remoteMod, localMod); return MakePtr(FARPROC, GetProcAddress(localMod, func), delta); } HMODULE GetRemoteModuleHandle(unsigned long pId, char *module) { MODULEENTRY32 modEntry; HANDLE tlh = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pId); modEntry.dwSize = sizeof(MODULEENTRY32); Module32First(tlh, &modEntry); do { if(!_stricmp(modEntry.szModule, module)) return modEntry.hModule; modEntry.dwSize = sizeof(MODULEENTRY32); } while(Module32Next(tlh, &modEntry)); return NULL; } PIMAGE_SECTION_HEADER GetEnclosingSectionHeader(DWORD rva, PIMAGE_NT_HEADERS pNTHeader) { PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION(pNTHeader); unsigned int i; for ( i = 0; i < pNTHeader->FileHeader.NumberOfSections; i++, section++ ) { DWORD size = section->Misc.VirtualSize; if ( 0 == size ) size = section->SizeOfRawData; if ( (rva >= section->VirtualAddress) && (rva < (section->VirtualAddress + size))) return section; } return 0; } LPVOID GetPtrFromRVA( DWORD rva, IMAGE_NT_HEADERS *pNTHeader, PBYTE imageBase ) { PIMAGE_SECTION_HEADER pSectionHdr; INT delta; pSectionHdr = GetEnclosingSectionHeader( rva, pNTHeader ); if ( !pSectionHdr ) return 0; delta = (INT)(pSectionHdr->VirtualAddress-pSectionHdr->PointerToRawData); return (PVOID) ( imageBase + rva - delta ); } int _tmain(int argc, _TCHAR* argv[]) { ULONG rc; STARTUPINFO StartupInfo; PROCESS_INFORMATION ProcessInfo; memset(&StartupInfo, 0, sizeof(StartupInfo)); StartupInfo.cb = sizeof(STARTUPINFO); StartupInfo.dwFlags = STARTF_USESHOWWINDOW; StartupInfo.wShowWindow = SW_HIDE; if (!CreateProcess( NULL, "c:\\windows\\system32\\calc.exe", NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &StartupInfo, &ProcessInfo)) { return 0; } WaitForSingleObject(ProcessInfo.hProcess, 5000); if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc)) rc = 0; MapRemoteModule(ProcessInfo.dwProcessId, /*ID_LOADER_DLL*/"c:\\bob.dll"); CloseHandle(ProcessInfo.hThread); CloseHandle(ProcessInfo.hProcess); return 0; } ---------

Create file, then increment by 1

$
0
0
Hey Guys, I'm looking for some code that works as follows:- I have a click box, whenever I press the button it creates a file in c:/results called results1.txt. the second time I press the button, if the file results1.txt exists it creates a new file called results2.txt and so on increasing the number. Would anybody be able to help please?

I am trying to Copy/paste one workspace variable from one to another in matlab

$
0
0
I have the Workspace variable BatteryDischargeCalc and I am trying to copy it into T. This was my attempt. T=BatteryDischargeCalc; It works in the command but not in the editor. Does anyone have a suggestion? Thanks

on events

$
0
0
what is the difference between (i) and (ii): (i) void DoEvents() { MSG msg; while(::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) return; } } (ii) void DoEvents() { MSG msg; while (::GetMessage(&msg, NULL, NULL, NULL)) { if (!PreTranslateMessage(&msg)) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } } }

Filling an array with random lines from a file

$
0
0
Hi I currently have a program that reads the first 10 lines from a text file and adds them to a vector array, however how would you instead choose lets say 100 random lines from the text file and place those into the vector array. Code: --------- const char newLine = 10; ifstream file("rockyou.txt"); vector arr; for (int i = 0; i < 10; i++) { string temp; file >> temp; arr.push_back(temp); } for (int i = 0; i < 10; i++) { cout << arr[i] << endl; } } --------- Thanks for any help you can provide.

An error in my code - binary digit matrix implementation by using 2D vector

$
0
0
Hello I'm doing a code in C++ which must execute a matrix in output contain binary digits, vertically. the programming environment is visual studio and when I use void in front of my 2D vector, I have one error, unfortunately, and I cannot solve this error when I use vectors which I commented in the following code without void function everything is okay and if I want to merge them into one vector like following with void function I will have an error in this line: HTML: --------- for (const auto& row : generate_mtx(nbits)) --------- please help me my code: HTML: --------- #include "stdafx.h" #include #include #include #include using namespace std; constexpr unsigned long long ubound(std::size_t nbits) { if (nbits < 2) return 2; else return ubound(nbits - 1) * 2; } //std::vector< std::vector > generate_mtx(std::size_t nbits) void generate_mtx(std::vector< std::vector >& result, std::size_t nbits) { nbits %= std::numeric_limits::digits; //std::vector< std::vector > result(nbits); // note: col with all zeroes is skipped (start with number = 0 to include it) for (unsigned long long number = 1; number < ubound(nbits); ++number) { auto n = number; for (auto& vec : result) { vec.push_back(n % 2); n /= 2; } } // to get the rows in the same order as illustrated in the example std::reverse(std::begin(result), std::end(result)); //return result; } int main() { if (size_t nbits = 4) { std::cout << "check matrix (H) is: " << std::endl; for (const auto& row : generate_mtx(nbits)) { for (int v : row) std::cout << v << ' '; std::cout << '\n'; } } int pause; std::cin >> pause; //return 0; } ---------

[RESOLVED] An error in my code - binary digit matrix implementation by using 2D vector

$
0
0
Hello
I'm doing a code in C++ which must execute a matrix in output contain binary digits, vertically.
the programming environment is visual studio and when I use void in front of my 2D vector, I have one error, unfortunately, and I cannot solve this error
when I use vectors which I commented in the following code without void function everything is okay and if I want to merge them into one vector like following with void function I will have an error in this line:

HTML Code:

for (const auto& row : generate_mtx(nbits))
please help me
my code:

HTML Code:

#include "stdafx.h"
#include <iostream>
#include <limits>
#include <vector>
#include <algorithm>
using namespace std;

constexpr unsigned long long ubound(std::size_t nbits)
{
        if (nbits < 2) return 2;
        else return ubound(nbits - 1) * 2;
}

//std::vector< std::vector<int>
> generate_mtx(std::size_t nbits)
void generate_mtx(std::vector< std::vector<int> >& result, std::size_t nbits)
{
        nbits %= std::numeric_limits<unsigned long long>::digits;

        //std::vector< std::vector<int> > result(nbits);

        // note: col with all zeroes is skipped (start with number = 0 to include it)
        for (unsigned long long number = 1; number < ubound(nbits); ++number)
        {
                auto n = number;
                for (auto& vec : result)
                {
                        vec.push_back(n % 2);
                        n /= 2;
                }
        }

        // to get the rows in the same order as illustrated in the example 
        std::reverse(std::begin(result), std::end(result));

        //return result;
}

int main()
{

        if (size_t nbits = 4)
        {
                std::cout << "check matrix (H) is: " << std::endl;

                for (const auto& row : generate_mtx(nbits))
                {
                        for (int v : row) std::cout << v << ' ';
                        std::cout << '\n';
                }


        }
        int pause;
        std::cin >
> pause;
        //return 0;
}

Random number generator with one for-loop

$
0
0
According to the following code which can generate random binary numbers, how I can decrease these two for-loops to one for-loop?

Code:

#include <iostream>
#include <string>
#include <ctime>
#include <vector>
using namespace std;

int main()
{
  std::vector<int> b;
  srand(time(0));
  for (int i = 1; i <= 11; i++)
  {
    b.push_back(i);
  }
  for (int i = 1; i <= b.size(); i++)
  {
  b[i] = rand() % 2;
  std::cout << b[i] % 2 << " ";
  }
}

Error while statically linking Libsodium

$
0
0
It appears that I'm linking libsodium correctly, but I'm getting linker errors for _sodium_init, I'm using Visual Studio 2015, and the libsodium.lib (prebuilt) for msvc 140 (for vs2015). The project is c++. This is how my setting look for linker: http://prntscr.com/ixv042 For additional includes, my settings look like this: http://prntscr.com/ixv0mg The folder that the project resides in looks like this: http://prntscr.com/ixv0vw I'm including sodium.h as so: http://prntscr.com/ixv1go and of course, in main() I'm doing Code: --------- sodium_init() --------- I'm not sure why I would be getting linker errors, does anyone spot anything wrong with the code?
Viewing all 3021 articles
Browse latest View live