Question

I have a problem with using unmanaged dll in my C# application. To be specific, I have this header file

Header

#ifdef RSAVREC_EXPORTS
#define RSAVREC_API __declspec(dllexport)
#else
#define RSAVREC_API __declspec(dllimport)
#endif

class RSAVREC_API CRsavRec {
public:
    CRsavRec(void);
};

RSAVREC_API void REC_stopRecordAvi(unsigned int chnIndex);

C# code

[DllImport("rsavRec.dll")]
private static extern void REC_stopRecordAvi(uint chnIndex);

private void button2_Click(object sender, EventArgs e)
{
    REC_stopRecordAvi(0);
}

On button2 click I got this message:

Unable to find an entry point named 'REC_stopRecordAvi' in DLL 'rsavRec.dll'.

Dll was compiled with VC6.

Thanks in advance.

Was it helpful?

Solution

You could try to use extern "C" on your unmanaged exported function:

extern "C" RSAVREC_API void REC_stopRecordAvi(unsigned int chnIndex)
{
    // implementation
}

You may also want to use __cdecl calling convention:

extern "C" RSAVREC_API __cdecl void REC_stopRecordAvi(unsigned int chnIndex)
{
    // implementation
}

OTHER TIPS

The following works for me:

in the .h

extern "C" 
{
    __declspec(dllexport) int __cdecl MethodName(parameters);
}

In the .cpp

extern int __cdecl MethodName(parameters)
{
   //Code
   ...

   return success;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top