|
When you use function overloading, the compiler generates a 'decorated' name for the function based upon the actual function name and the argument signature. Using your function names, the compiler might generate the name 'readNumber@4 ' for 'readNumber(int) ', and 'readNumber@8 ' for 'readNumber(double) '. This lets the linker, which doesn't know anything about function overloading, tell the two functions part.
This should tell you why dynamic loading based on the name 'readNumber ' alone isn't going to work. There's no way for the loader to know which version of the function you are asking for.
The simplest solution is to continue using the extern "C" approach you have been, and 'decorate' the names yourself.
Software Zen: delete this;
|
|
|
|
|
|
How do i convert an integer to string?
Is that really necesary if i want to paint some integer values on a win32 programm? or is there some function similar to TextOut that can paint integer values?
Thank you
|
|
|
|
|
Use itoa() or sprintf() to convert an integer to a string.
Pacificat0r wrote: Is that really necesary if i want to paint some integer values on a win32 programm? or is there some function similar to TextOut that can paint integer values?
Yes, it is necessary. If you think about it, it doesn't make sense for the Windows API to provide a 'paint an integer' function in addition to all of the 'paint text' functions. 'Paint text' functionality supports anything that can be represented as text. Converting that 'anything' to text is just a second operation that can be implemented separately, and doesn't have to be maintained as part of the Windows API.
Software Zen: delete this;
|
|
|
|
|
I'd do it like this:
std::ostringstream ss;
ss << "The number is " << 42;
TextOut(hDC, 0, 0, ss.str().c_str(), ss.str().length());
Naturally you'll need to include <sstream>
Steve
|
|
|
|
|
|
This is silly! Yes it is necessary, but the programming language or the compiler vender may provide a method for doing it for you (another programmer). If you really want to be a programmer, then you should be able to recreate the code to do the conversion. The others have showed you the methods provided to do the conversion (which you should use), but you are not a programmer until you can write a method to do it your self.
INTP
Every thing is relative...
|
|
|
|
|
thank you for your help
|
|
|
|
|
Hi one, hi all!
I have recently ported from WiInet to WinHttp in my server application.
Everything works just fine but there is one major question regarding some flags that were set in the WinInet HttpOpenRequest(…). The dwFlags had values of INTERNET_FLAG_KEEP_CONNECTION and INTERNET_FLAG_NO_CACHE_WRITE which I need to use, the problem is I can not find the equivalent in the WinHttp API protocol!!! I was told to add it the Headers of the request in format of:
"Content-Type: application/x-www-form-urlencoded\r\n Connection : Keep-Alive\r\n Cache-Control: no-cache"
but it seems rather strange to set flags as part of the message sent to the server!
Any one?
Thanks
S
|
|
|
|
|
|
You've got a couple options here.
1. If the file is relatively small, read the entire file into a string and then use one of the string search functions (like strstr ) to find the opening marker <<A>>. Extract the data from where you find it.
2. If the file is large, read it a chunk at a time. Look for the first character in the marker in the chunk. If you find it, read enough more out of the file, appending to the chunk, that you're sure you have all of the data you're interested in. Extract the data.
3. Given your example, it almost sounds like you're trying to read XML. If that's the case, there's plenty of code around for helping you do that.
Software Zen: delete this;
|
|
|
|
|
1. no - I'm not trying to read an XML file. I'm trying to read a picture file that has a header from which I'm trying to extract the string... when I open the picture file with a text editor I see the string I have to read... and yes, the file is big...
2. How can I read chunk by chunk? with the read function?
right now, I'm reading like this:
int MaxBufferSize = 1000;
char cTemp[MaxBufferSize + 1];
cf.Read(cTemp, MaxBufferSize);
//then look for the string in the cTemp array.
is this the correct way to do this?
how can I search for the string in the cTemp array? with a for loop?
|
|
|
|
|
Try looking up the strstr function, which searches for one string within another.
You can also do the search yourself by looping through the data, something like this:
for (int offset = 0; offset < MaxBufferSize; offset++) {
if (CTemp[offset] == '<') {
if (strcmp(&CTemp[offset],"<<A>>") == 0) {
}
}
}
Software Zen: delete this;
|
|
|
|
|
This loop will not work. The strcmp function matches two NULL terminated strings - As such it will never match the sequence unless it's at the end of the buffer (the only place where it could be NULL terminated).
Steve
|
|
|
|
|
|
Try this:
CFile cf(sCurrImgPath, CFile::modeRead);
const int MaxBufferSize = 100000;
char cTemp[MaxBufferSize + 1];
const char *pStringToFind = "<<A>>";
size_t LengthOfStringToFind = strlen(pStringToFind);
while (pStr == NULL)
{
iBytesRead = cf.Read(cTemp, MaxBufferSize);
pStr = strstr(cTemp, pStringToFind);
if ( pStr != NULL )
{
pStr += LengthOfStringToFind ;
}
}
Steve
|
|
|
|
|
Ok - it still doesn't work....
I think the problem is that I am trying to read text from a file which is actually an image file.
I'll explain my problem in a different manner...
what I have is a *.png file (image file), which has a row of text somewhere in the file. This row starts with: >tEXtComment, and continues with the data I need to read...
how can I extract this row that starts with ›tEXtComment from the image file?
|
|
|
|
|
Before you worry about that test your code on a plain text file you create.
Steve
|
|
|
|
|
Ok - so I copied the string to a text file and renamed it as a *.png file, and it finds the string, and works fine...
|
|
|
|
|
Ok. Now open the .png file with Notepad and see it actually contains the string.
Steve
|
|
|
|
|
what .png file? I didn't understand what u meant..
I already opened the .png files with notepad, and they all contain the string. That includes the .png file that is the actual image, and the .png file I just created...
|
|
|
|
|
I can't think of what could be going wrong then. If it finds it the text file it should work for the image file - assuming the string is present. The only think I can suggest is to check that the cases are consistent. i.e. Search string is in upper cast but string in file is in lower case.
Steve
|
|
|
|
|
I'll tell u something - I copied all of the data from the .png file that is an image file(the original file), to the .png file I constructed from Notepad, and the search for the string works...
So I think the problem is in the fact that the original .png file was originally constructed as an image file...
|
|
|
|
|
Oops. That should have been strncmp .
Software Zen: delete this;
|
|
|
|
|