|
Easy one first:
GC104 wrote: Sprintf(BasicString, "ABCDDEF") : Bad because I haven't initialised it as soon as I declared it? or the fact that I'm using sprintf to load the string?
Bad because it wasn't char BasicString[100]; when I answered the question - it was (IIRC) char* BasicString
Also - sprintf is less than optimal for assigning a string to another string - strcpy is better, I guess.
GC104 wrote: Any suggestions for an alternative to CW2A macro?
CW2A isn't a macro. It's a class. There are a few alternatives:
- Make sure that pOutputString has storage associated with it and strcpy the CW2A into it:
char pOutputString[1024];
strcpy(pOutputString, CW2A(TxString));
- Declare pOutputString to be of type CW2A and assign TXString to it. THat way the storage is associated with the lifetime of pOutputString, which is what you want:
CW2A pOutputString = TxString; - Declare pOutputString to be of some other ASCII string type and assign CW2A(TXString) to it. That way there is storage associated with the lifetime of pOutputString, which is what you want:
std::string pOutputString = CW2A(TxString);
I'd go for option 2, personally.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I am learning to use VS2005 creating a VC++ MFC project to unterface to serial ports. I am in the initial stages of getting to grips with creating a serial port class. I am finding a few problems along the way with vartiable / data member initialisation.
CGCSerial h-file
int CharCount;
int CharCount2;
int CharCountThree;
CString TxString;
size_t InputStringLength;
TCHAR * pStr;
char * pOutputString;
cpp-file(s)
CMyDrawView::OnToolWrite2SerialPort
//member function called by clicking on windows menu item
{
CGCSerial *pGcSp = new CGCSerial(_T("12345")); //create instance of CGCSerial class
pGcSp -> GCTx; //call transmit member function
delete pGcSp; //cleanup
}
CGCSerial::GCSerial(TxString)
{
//constructor
CharCount2 = 0
CharCountThree = 0;
}
CGCSerial::~GCSerial
{
//destructor
}
CGCSerial::GCTx
{
InputStringLength = wcslen(TxString); //measuring length of incoming string
CharCountThree = sizeof(InputStringLength); //load CharCount3 with something
TempString.Format(_T("executing function CGCSerial::GCTx"));
AfxMessageBox(TempString);
pStr = TxString.GetBuffer(256);
CharCount2 = sizeof(pStr);
TxString.ReleaseBuffer;
InputStringLength = wcslen(pStr); //measuring length of
CharCount2 = 0x2345; // ###
CharCountThree = 0x5678; //###
CharCount2 = sizeof(TxString);
CharCountThree = sizeof(pOutputString);
pOutputString = CW2A(TxString); //convert wide string to ANSI string
...
...
}
My problem is that I admit this code doesn't look the most useful and is due to getting to grips with VC++ functions. The lines marked with ### don't seem to get executed! If I use the debugger, the debugger stops at these lines but upon viewing these data member's they do not get loaded with 0x2345 & 0x5678 respectively??? Is this a compiler bug??
any help would be greatly appreciated
modified on Tuesday, September 8, 2009 8:21 AM
|
|
|
|
|
GC104 wrote: CharCount2 = 0x2345; // ###
CharCountThree = 0x5678; //###
CharCount2 = sizeof(TxString);
CharCountThree = sizeof(pOutputString);
Maybe the compiler optimizes that to:
CharCount2 = sizeof(TxString);
CharCountThree = sizeof(pOutputString);</blockquote>
BTW please use the code block to submit code snippets.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Could it be that you are debugging a release build?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Hi all,
Thanks for responses. It looks like CPallini nailed it - the compiler doing its job! I have since added more data members to capture the results of the various functions I used on the original code. However this time, the debugger runs through eacdh line and loads each variable with the value I was expected
many thanks
Geoff
|
|
|
|
|
Hi every body!
Is there any way/tool to find out which module creates a specific file? E.g one can see a process named Process.exe and this process has loaded a few DLL. What I want to know is which of theses DLLs creates a given file (e.g. C:\file.ext)
Thank you masters!
|
|
|
|
|
unless you have the source code to the dll, I doubt it after the file has been created and closed. If the file is open, there are tools around that are the windows equivalent of the 'lsof' command - systinternals (now part of Microsoft) has a tool to display (iirc) open files vs the processes that have them open
'g'
[edit] I was wondering if the file properties (custom) would be useful, but surely that depends on a well behaved application filling them out in the first place[/edit]
|
|
|
|
|
Thank you for your answer. I meant something like that I can examine a specific DIRECTORY or FOLDER so that I can catch every process that attamps to create or modifiy a file.
Thank you masters!
|
|
|
|
|
|
Further to R.selvam's answer - FileMon's been deprectaed - MS recommend you use ProcMon[^] now. That allows you to capture more than just file accesses, for example registry accesses as well.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
You don't need any tool, just use NAPI
|
|
|
|
|
If an API is not a tool, then please tell us what it is?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I am learning to use VS2005 to create a VC++ MFC project to read from the serial port using the 'ReadFile' function. in particular I am having problems getting the code to compile 'ReadFile' parameter 4:
h-file
...
DWORD ActualBytesRead
DWORD * pActualBytesRead
...
cpp-file
attempt 1:
pActualBytesRead = &ActualBytesRead
ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, pActualBytesRead, NULL)
-compiles, but parameter 4 ends up with 0xbaadF00d at the time of the 'ReadFile' call?
attempt 2:
ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, &ActualBytesRead, NULL)
-compiles (passing by reference?)
attempt 3:
pActualBytesRead = &ActualBytesRead
ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, *pActualBytesRead, NULL)
-won't compile?
OK, so I have a version of code that compiles but I don't really understand why attempt 1 & 3 fail?
modified on Tuesday, September 8, 2009 11:06 AM
|
|
|
|
|
1 and 3 fails because you're passing a DWORD** instead of DWORD* .
The following should compile.
DWORD ActualBytesRead = 0;
BYTES ReceiverBuffer[1024];
DWORD NumberOfBytes2Read = 1024;
ReadFileStatus = ReadFile(SerialPortHandle, ReceiverBuffer, NumberOfBytes2Read, &ActualBytesRead, NULL);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: 1 and 3 fails because you're passing a DWORD** instead of DWORD*.
Actually, in the first case he is passing a DWORD* (so this should compile) and in the third case he is passing a DWORD.
|
|
|
|
|
GC104 wrote: ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, pActualBytesRead, NULL)
-won't compile, even though I am passing a pointer to a 'DWORD'?
This compiles for me.
GC104 wrote: ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, *pActualBytesRead, NULL)
-won't compile?
Because argument 4 is the contents, or value, of pActualBytesRead .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Since posting the original message, I would expect attempt 1 to compile. Is this likely to be a quirk in the VS2005 VC++ compiler? Many thanks for thoughts.
Geoff
|
|
|
|
|
Without seeing the actual error message, I've no idea.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Sorry, I made a typo whilst trying 'attempt 1'. Yolu're right it does compile, the problem is that pActualBytesRead gets loaded with 0xbaadf00d prior to the 'ReadFile' call.
Thanks for help
|
|
|
|
|
Hi,
I try to get the current position of pointer in the stream (IStream interface) with the method Seek (IStream::Seek Method) but i can't succeed to do this.
So can someone help me how to do this OR if there is an other method to get the current position from this stream?
thank you
|
|
|
|
|
Ummm - try this:
ULARGE_INTEGER currPos;
LARGE_INTEGER offset;
offset.QuadPart = 0;
istreamInterfacePointer->Seek(offset, STREAM_SEEK_CUR, &currPos);
Zero offset from the current position will be the current position...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you , it work
can you please help me again and tell me how can use Seek to get the size of the current stream ?
thanks
|
|
|
|
|
ULARGE_INTEGER currPos;
LARGE_INTEGER offset;
offset.QuadPart = 0;
istreamInterfacePointer->Seek(offset, STREAM_SEEK_END, &currPos);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi to All,
I need help in understanding the difference between copy constructor and assignment operator, and when do we use them exactly,...and with contrast of shallow and deep copy too.
I tried to understand from internet, but still I didn't get a clear picture of it.
Could someone please put some light for the same.
Thanks in advance.
-----------------------------
I am a beginner
|
|
|
|
|
MyClass a;
MyClass b(a);
MyClass c = b;
MyClass d;
d = c;
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|