1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HELP : Getting junk Chars in C# Dll while calling function through VC++

Discussion in 'C#' started by sisrahul, Jul 4, 2007.

  1. sisrahul

    sisrahul New Member

    Joined:
    Feb 26, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi All

    Been trying to figure out a solution to this problem since long. Would appreciate if someone can throw some light.

    I am calling a managed C# dll in VC++ code. My problem is that I'm unable to pass the bstr data from VC++ to C#. In fact, the bstr data is coming to C#, but its all junk values that looks something like this...

    瑨ç´â¼ºã„¯ãˆ¹ã„®ã ¶ã„®ã„°ã„®ãŒ°æœ¯â½·ç•°å½´ç¡¸â¹¸æ¡°p.280ã…—Ä„

    Though if I pass a data of type "int", I get the correct value in C#. The problem is with the bstr values. This is how my code is in VC++...

    unsigned char* URL ;

    I have typecasted this unsigned char* into a binary string as following



    BSTR PURL =SysAllocString((BSTR)URL.p);

    and call a function in VC++ written in C# dll as following

    pIclass1->raw_HTTP_Put_Query (&PURL ,nBufLen,&retVal );





    In C# I receive the values as following

    public int HTTP_Put_Query(ref string PURL,int nBufLen)

    {

    ....

    .....

    }





    Now, the problem is that the PURL parameter of type "bstr" recieves junk values in the C# dll, the nBufLen variable being of type "int" is getting correct value.

    Is there a way I can convert the bstr to string so that it doesnt return junk values?

    Would really appreciate much needed help.





    Thanks

    Rahul
     

Share This Page