Search code examples
c#pinvoke

C# Pinvoke of C Code issue


What I am trying to do: I have some embedded C code which does some signal processing. I also have a set of C# tools. I would like to use the C# code to be call the embedded C code with some waveforms to 'test' the algorithm and see what it is thinking/doing.

What I did:

Embedded C code:

__declspec (dllexport) void SigInit(int Flag);   
void SigInit(int Flag) {  ... } 

I compile as a Win32 DLL. Configuration type is "Dynamic Library (.dll)" and MFC is set to "Uses Standard Windows Libraries". I "viewed" my library in the Visual Studio 2010 Class viewer and everything looks good.

Then in my C# code (VS2010 with .NET 4.0):

public static class ProcessSignals
{

    [DllImport(@"C:\Users\rpease\Desktop\SigLibrary.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern void SigInit(int Flag);
}

But whenever I try to run the main program and call ProcessSignals.SigInit(0):

Unable to find an entry point named 'SigInit' in DLL 'C:\Users\rpease\Desktop\SigLibrary.dll'.

I was thinking this was a name-mangling issue but thought I took care of that. Suggestions appreciated. I think I am following the guidelines in: PInvoke DLL in C# but can't get past this.

Thanks,

Roger


Solution

  • Open a Visual Studio command prompt and change directory to the the folder that contains the DLL in question, and then run:

    dumpbin <nameOfDll> /exports
    

    (where <nameOfDll> is the filename of your DLL file, without the angle brackets)

    Do you then see the name of the function you are expecting listed?