DllImport错误:无法找到名为的入口点 [英] DllImport error: unable to find an entry point named

查看:163
本文介绍了DllImport错误:无法找到名为的入口点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为WD_SDK.dll的DLL文件(它与SDK.h文件一起使用)。我打开SDK.h,我看到



  typedef   void (CALLBACK * VideoCaptureCB_Ptr)(PVOID pContext,BYTE * apData [ 3 ],
VideoSampleInfo_T * pVSI );

typedef struct _VideoSampleInfo_T
{
ULONG idFormat ; //
ULONG lSignalState;
int nLen; // 未用于原始视频数据(例如YUV420)
int nWidth;
int nHeight;
int anPitchs [ 3 ]; // 仅用于原始视频数据(例如YUV420)
ULONG dwMicrosecsPerFrame; // 1000 * 1000 / FPS
ULONG字段;
int iSerial;

} VideoSampleInfo_T;

WD_RegisterVideoPreviewCB(HANDLE hChannel,PVOID pContext,VideoCaptureCB_Ptr pCB);





我想调用WD_RegisterVideoPreviewCB in C#。所以我使用DllImport在C#中声明它。它看起来像这样:



 [DllImport(  WD_SDK.dll,EntryPoint =   _ WD_RegisterVideoPreviewCB @ 12,ExactSpelling =  true )] 
静态 extern int WD_RegisterVideoPreviewCB( IntPtr hChannel, object pContext,VideoCaptureCB_Ptr pCB);







然后我重新声明C ++结构和C#中的CALLBACK如下:



  public   delegate   void  VideoCaptureCB_Ptr( IntPtr  pContext, byte  [] apData,Video SampleInfo_T pVSI); 

[StructLayout(LayoutKind.Sequential)]
public struct VideoSampleInfo_T
{
public uint idFormat;
public uint lSignalState;
public int nLen; // 未用于原始视频数据(例如YUV420)
public int nWidth;
public int nHeight;
public int [] anPitchs; // 仅用于原始视频数据(例如YUV420)
public uint dwMicrosecsPerFrame; // 1000 * 1000 / FPS
public uint 字段;
public int iSerial;

}





和一个代表工具



当我运行我的代码时



 WD_RegisterVideoPreviewCB(m_ahChannels [i],m_aMediaHandler [i],HandleVideoStatic); 





程序显示错误与非托管目标签名不符。



我认为遇到了PVOID pContext的问题,我将其更改为对象pContext。但是我必须将m_aMediaHandler [i](它是一个类的实例而不是指针)传递给它,错误引发..无效的agruments



请帮我纠正这段代码。提前谢谢。

解决方案

我不知道你在哪里得到了_WD_RegisterVideoPreviewCB @ 12。这个名字看起来很现实,但是更好的检查。



最简单的方法是在导出的DLL上运行一些二进制转储实用程序。它可以是DUMPBIN.EXE:

http://msdn.microsoft.com/en-us/library/c1h23y6c.aspx [ ^ ]。



您可以从Visual Studio菜单中的Visual Studio命令提示符运行此实用程序。



- SA

I have an DLL file named WD_SDK.dll ( it go with an SDK.h file ). I open the SDK.h and I see

typedef void (CALLBACK * VideoCaptureCB_Ptr)(PVOID pContext, BYTE * apData[3],
VideoSampleInfo_T * pVSI);

typedef struct _VideoSampleInfo_T
{
    ULONG   idFormat; // 
    ULONG   lSignalState;
    int     nLen; // not used for raw video data(e.g. YUV420)
    int     nWidth;
    int     nHeight;
    int     anPitchs[3]; // only used for raw video data(e.g. YUV420)
    ULONG   dwMicrosecsPerFrame; // 1000*1000/FPS
    ULONG   field;
    int     iSerial;

} VideoSampleInfo_T;

WD_RegisterVideoPreviewCB(HANDLE hChannel, PVOID pContext, VideoCaptureCB_Ptr pCB);



I want to call the WD_RegisterVideoPreviewCB in C#. So I use the DllImport to declare it in C#. It look like this:

[DllImport("WD_SDK.dll", EntryPoint = "_WD_RegisterVideoPreviewCB@12", ExactSpelling = true)]
        static extern int WD_RegisterVideoPreviewCB(IntPtr hChannel,  object pContext, VideoCaptureCB_Ptr pCB);




Then i re-declare the C++ struct and CALLBACK in C# like this:

public delegate void VideoCaptureCB_Ptr(IntPtr pContext, byte[] apData, VideoSampleInfo_T pVSI);

[StructLayout(LayoutKind.Sequential)]
    public struct VideoSampleInfo_T
    {
        public uint idFormat;
        public uint lSignalState;
        public int nLen; // not used for raw video data(e.g. YUV420)
        public int nWidth;
        public int nHeight;
        public int[] anPitchs; // only used for raw video data(e.g. YUV420)
        public uint dwMicrosecsPerFrame; // 1000*1000/FPS
        public uint field;
        public int iSerial;

    }



And one delegate implement

When i run my code

WD_RegisterVideoPreviewCB(m_ahChannels[i],  m_aMediaHandler[i], HandleVideoStatic);



THe program show me an error "does not match the unmanaged target signature. "

I thinks encountered problem with the PVOID pContext, I changed it to object pContext. But i have to pass the m_aMediaHandler[i] ( It's an instance of a class not a pointer ) to it, the error raised " .."invalid agruments"

Please help me to correct this code. Thanks in advance.

解决方案

I don't know where did you get "_WD_RegisterVideoPreviewCB@12". This name looks realistic, but better check it up.

The simplest way to do so is running some binary dump utility on your exported DLL. It can be DUMPBIN.EXE:
http://msdn.microsoft.com/en-us/library/c1h23y6c.aspx[^].

You can run this utility from the Visual Studio Command Prompt found in Visual Studio menu.

—SA


这篇关于DllImport错误:无法找到名为的入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆