Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[4451] Hosting Control Panel Applets using C#/C++

Last post 11-10-2004 11:56 AM by rkabir. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [4451] Hosting Control Panel Applets using C#/C++

    This thread is for discussions of Hosting Control Panel Applets using C#/C++.

    • Post Points: 0
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 03-24-2004 10:03 AM In reply to

    • mal
    • Not Ranked
    • Joined on 03-23-2004
    • New Member
    • Points 10

    dllImport attribute & STLstring parameter

    This article is very useful to understand how to call unmanaged function from C#.net. I have to do the same thing for my project but it seems little complex as it is passing user defined data type as an argument to the calling function. I will appreciate help with this.
    Unmanaged C++ function which I am trying to call from C#.net app. is as below: (from the header file)

    static void LibAction(const libString& actionXML, libString& returnXML, libError& libError);

    libSting is a reference to the container class - wraps Standard Teplate Library String type. declared in the header file as below:

    class LIB_CLASS_EXPORT LibString : public std::string
    {
     typedef std::string STL_STRING;
    public:

     // --- Constructors/Destructor ---
     
     LibString() { ; }
     LibString(const LibString& S);
     LibString(const char* s);
     LibString(char s);
     LibString(istream&);
     LibString(const STL_STRING & S) : STL_STRING(S) { ; }
     virtual ~LibString();


    libError is a reference to the container class which is used for the error handling.

    How do I call this function from C# windows application.

    Below is how I am trying to declare above function in my C# app.

    [DllImport(@"C:\Test\dlls\Lib.dll", EntryPoint="LibAction")]
    public static extern void LibAction(string actionXML, string returnXML, string libError);

    Instead of string I should be passing ref to the libString. I am not sure how do I do that in C#.

    Please help.




    • Post Points: 0
  • 04-16-2004 5:20 PM In reply to

    • leedm777
    • Not Ranked
    • Joined on 04-16-2004
    • New Member
    • Points 5

    none

    Sorry, I had a comment, but it was a mis-understanding of the original post.
    • Post Points: 0
  • 11-10-2004 11:56 AM In reply to

    • rkabir
    • Not Ranked
    • Joined on 11-10-2004
    • New Member
    • Points 5

    Simple Solution for MAKEINTRESOURCE problem in C#

    Hi,

    have also tried to convert the ambigous #define MAKEINTRESOURCEW(i) (LPWSTR)((ULONG_PTR)((WORD)(i))) in C++ into C# but with no luck.
    So I compiled a C++ program using MAKEINTRESOURCE and traced it to see what TYPE is really passed to UpdateResource(..) or similar resource accessing functions. What I hav efound that it actaully passes the interger value (Resource ID). For example if you have a Resource with "MY_RES_ID" with ID 129
    the compiled code actaully just passes the 129 as a WORD data.

    So in C# while doing DllImport, I just chaged the Data Type for the Resource Id parameter which uses MAKEINTRESOURCE.
    Here is what I did with UpdateResource

    [DllImport("kernel32.dll")]
    static extern bool UpdateResource(IntPtr hUpdate, string lpType, int lpName,  ushort wLanguage, IntPtr lpData, uint cbData);

    Notice the Third param which has been chaged from String to int. And It works!!!  Now you will just pass (using my example as mentioned above) 129 instead of MY_RES_ID, or directly MY_RES_ID if it is defined somewhere to reprent 129.



    ----
    Rezaul Kabir
    shuvro@yahoo.com
    • Post Points: 0
Page 1 of 1 (4 items)