Old 7th December 2011, 17:24   #1
jrlarkin87
Junior Member
 
Join Date: May 2010
Posts: 14
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!?
jrlarkin87 is offline   Reply With Quote
Old 7th December 2011, 17:56   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
That is a pointer to the first character of the string. Use pushstring to push it onto the stack.

Stu
Afrow UK is offline   Reply With Quote
Old 7th December 2011, 18:37   #3
jrlarkin87
Junior Member
 
Join Date: May 2010
Posts: 14
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 is offline   Reply With Quote
Old 7th December 2011, 19:12   #4
jrlarkin87
Junior Member
 
Join Date: May 2010
Posts: 14
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?
jrlarkin87 is offline   Reply With Quote
Old 7th December 2011, 21:30   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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 is offline   Reply With Quote
Old 7th December 2011, 22:35   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump