Results 1 to 2 of 2

Thread: Call C++ Functions in C# (.NET 4.5)

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    829

    Call C++ Functions in C# (.NET 4.5)

    Good Day

    I have a C++ Dll that has the following functions

    Code:
    void DisplayError( HWND hDlg, WPARAM wParam )
    HRESULT ValidateI2CDeviceEx( HWND hDlg, ULONG i2cBase, PULONG pAccessBytes )
    BOOL ValidateSetValue( HWND hDlg, char *str )
    BOOL ValidateIdxValue( HWND hDlg, char *str )
    ULONG atox( LPSTR s )
     EnableGroupBoxes( HWND hDlg )
    LRESULT CALLBACK EM2800PropProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
    LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
    LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
    VOID DestroyEM2800Prop()
    VOID InitEM2800Prop()
    ATOM MyRegisterClass( HINSTANCE hInstance )
    BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
    int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                          LPSTR lpCmdLine, int nCmdShow )
    i would like to use this non-com dll in C#

    Thanks
    Attached Files Attached Files

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: Call C++ Functions in C# (.NET 4.5)

    You call all such functions in the same way as you do Windows API functions, which means declaring a C# function with a compatible signature and decorating it with the DllImport attribute to tell .NET where and how to map the call to the external function.

    http://social.msdn.microsoft.com/Sea...rt%20c%23&ac=3

    As for what data types to use, many of them should be fairly obvious, e.g. bool for BOOL. For all the handles you should use IntPtr. You can use IntPtr for the WPARAM and LPARAM parameters too, although it may be more convenient to use 'int'.

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