Click here to Skip to main content
15,892,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to call method and event which written in c(c native api).
and want to use of ABC.dll (or ABC.lib for static link) with the C and the C++ interfaces.

CSS
C functions are described in ABC_Functions.h ;
C/C++ ABC error codes are descibed in ABC_Errors.h ;
C++ enumerations and constants are described in ABC_Types.h ;
C++ classes and methods are described in ABC_Classes.h ;
any of them can be used by including ABC.h in the project that needs ABC capabilities.


My code is
C#
[DllImport("ABC.dll",CallingConvention = CallingConvention.StdCall)]
    static extern void  ABC();
    [DllImport(" ABC.dll", CallingConvention = CallingConvention.StdCall)]
    static extern IntPtr GetDisplay();
    [DllImport(" ABC.dll",CallingConvention = CallingConvention.StdCall)]
    static extern IntPtr SetDisplay(IntPtr displayhandle);
    [DllImport(" ABC.dll",  CallingConvention = CallingConvention.StdCall)]
    static extern Int32 GetNumberOfDevices();



On button click

C#
private void button1_Click(object sender, EventArgs e)
       {
           try
           {
               SetDisplay(this.Display.Handle);
               GetDisplay();
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }

msg is
"Unable to find an entry point SetDisplay" in DLL ABC.dll
Posted
Updated 30-Mar-14 20:12pm
v2

1 solution

About calling a function: the problem is very simple: there is no such method in "ABC.DLL". Before writing your P/Invoke code, check up what is exported and under what name (a name can be mangled: http://en.wikipedia.org/wiki/Name_mangling[^]).

You can use some binary dump utility, such as dumpbin.exe, which you can call from the Visual Studio Command Line:
http://support.microsoft.com/kb/177429[^],
http://msdn.microsoft.com/en-us/library/c1h23y6c.aspx[^],
http://msdn.microsoft.com/en-us/library/20y05bd5.aspx[^].

About "calling an event": in this part, the question makes no sense at all. 1) There is no such notion as "call an event". 2) In native API, there are no "events", nothing like you have in .NET. Even in .NET: events are not called, they are invoked (very, very different concept); besides, you cannot invoke them from anywhere except their declaring types.

—SA
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900