Click here to Skip to main content
14,271,310 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have C Dll with number of functions. Some of them return very big numbers by char buffers. I get Chinese in these buffers. What can I do for arranging these buffers for getting numbers in buffer and not Chinese symbols?
Jochen Arndt 19-Jun-12 5:20am
The documentation of the DLL should contain information on the returned data and how the data can be interpreted. Using a C type char buffer to pass values does not always mean that the result is some kind of text. Char buffers are also often used to pass binary values.
If these comments does not apply to your question, you should give some more information with code snippets.
Rate this:
Please Sign up or sign in to vote.

Solution 1

They probably aren't returning Chinese characters specifically, but a sequence of bytes which form the number. Since the byte values are 0 to 255 inclusive, they are displayed as odd symbols if you try to display them.

You will have to look at your DLL documentation and find out what format the very large numbers are returned in: since we don't know what DLL you are referring to, we can't even guess this! You may find that the DLL contains functions for converting the very large numbers to and from printable strings.
MayIsONe 19-Jun-12 8:34am
I built C Dll and I call it from VB application. After calculation of big number D I put the result to char buffer chD and after that I can pass it to VB application by the function
BSTR __stdcall GetRSAKey_D()
BSTR bstr = SysAllocString((OLECHAR *)chD);

return bstr;
In VB application I got buffer has been filled with Chinese symbols.
OriginalGriff 19-Jun-12 9:07am
Just returning it as a BSTR does not convert it from a byte sequence, it just lets the VB code look at it as characters - which will show you rubbish.
Either handle it as bytes in the VB (which is the safe way as characters are subject to interpretation as Unicode which you don't want for an RSA Key) or convert it to a decimal or hex string before returning to from the C code.
Rate this:
Please Sign up or sign in to vote.

Solution 2

int __stdcall RSA_EncryptMessage_Ex(char * pmsg, BSTR* bstrM, int nMsgSz, int nBits)
    int iSize = 0;
    wchar_t wcstring[KEYSIZE];

    if (RSA_EncryptMessage(chM, pmsg, chN, chD, chE, nMsgSz, nBits) != 0)
        return -1;

    iSize = 2*strlen(chM);
    _snwprintf(wcstring, iSize, L"%S (wchar_t *)", chM);
    *bstrM = SysAllocStringByteLen((LPCSTR)wcstring, iSize);

    return 0;

First, variables by ref. must be of the type BSTR.
Second, I transformed the char array to wide char. BSTR. So, it's working!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100