CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Jun 2005
    Posts
    7

    Angry DllImport problems with c-style char arrays

    Hi guys,

    I have function written in C

    extern "C" __declspec(dllexport) char * receiveSTATUS()
    {
    ....
    ....
    }

    that returns a pointer to a string of characters. This function is in a dll file (pfserver.dll) which i have imported into a C# .NET application using the DLL import attribute like...


    [DllImport("pfserver.dll")]
    public static extern string receiveSTATUS();

    so i presume the c-style char array gets marshalled into a string in C#. The function is called in the C# app like...

    string str = receiveSTATUS();

    This method works for the most part but sometimes the string str (received in the C# app) has some garbage values in the beginnig few places e.g.

    string to be returned "192.168.1.10|-"
    string received "!,##!,#.1.10|-"

    (the #'s are garbage characters that dont have a print representation and get printed as rectangles)

    Most of the time this works... i.e I get the correct string back into the C# app but sometimes this weird garbage gets returned. I have no idea how to fix this. Maybe i need to do some marshalling using MarshalAs ?

    Thanks for your help in advance

    Z
    Last edited by zubinr; July 28th, 2005 at 03:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured