jrlarkin87
7th December 2011 18:24 UTC
Plugin C++ Returning Garbage
Hi guys,
I am not sure this applies to this forum but not sure where else to ask. Currently I am creating a Plugin for C++. I am using OBDC to connect to database. When I run the connection its returning me an unsigned char*. I want to return that unsigned char* to NSIS. When I display it using cout it seems to work! When I try to type cast it Ex. (char)variablename, it is returning me J followed by some weird characters looks like a U with a carrot on top and a Box. Is there some kind of special conversion I need to do for the NSIS? When I convert and display in a consule app I built for testing I didn't have this problem!?
Afrow UK
7th December 2011 18:56 UTC
That is a pointer to the first character of the string. Use pushstring to push it onto the stack.
Stu
jrlarkin87
7th December 2011 19:37 UTC
I am here is a little more code hopefully this will help to see what I did wrong:
unsigned char VarA[2048];
(I send it to a some database function and it fills it up with goop which is displayed in a consule app I created for debug using cout)
pushstring((const char*)VarA);
jrlarkin87
7th December 2011 20:12 UTC
I just noticed that if I take the unsigned character out of the picture and just use something like char* test[255] = "Test Text"; then it works fine? Could this mean the problem is related to the way I am casting the Unsigned Character?
Afrow UK
7th December 2011 22:30 UTC
Do you need to use unsigned char? Also you shouldn't allocate a fixed size buffer of 2048 because NSIS can only handle strings of 1024 unless you rebuild it (or use the 8192 special build). You should allocate a buffer at run time with LocalAlloc using string_size * sizeof(char) as the number of bytes where string_size is provided by NSIS (then use LocalFree when done).
Stu
Afrow UK
7th December 2011 23:35 UTC
I have no problem casting to a char* so it sounds to me like the database is returning data in a format that isn't char[]. Perhaps it's Unicode characters?
Stu