#define PLAYBACKENGINE_API __declspec(dllimport)
class PLAYBACKENGINE_API CPlaybackEngine 
{
public:
    //First of all, caller MUST call Initialize
    //in one process, this should be called only once
    static int Initialize(const char *pParam);
    static void UnInitialize();
    
    //Create Playback Engine using Singleton Pattern
    //Directly create is prohibited
    static CPlaybackEngine *getInstance(int nIndex = 0);
    static void releaseInstance(int nIndex = 0);    //parameter setting
    int EnableDDraw(bool bEnable, HWND hwnd);
    int SetDisplayHDC(HDC hdc);
    int SetDisplayRange(int x, int y, int nWidth, int nHeight);
    int SetVideoAutoScale(bool bAutoScale);
    int SetLantencyTime(int nMilliSeconds);
        
    //load will enter loaded state,
    //unload will return to init state
    int Load();
    int Unload();    int SetMode(enum MP_ENG_MODE mode);上面是C++类的头文件。C++例子中的调用代码如下:
   pPlayer = CPlaybackEngine::getInstance();
   pPlayer->SetMode(MP_MODE_SERV_PROXY);
   pPlayer->SetCallbackFunc(myEventCallBack, this);
   pPlayer->Load();
   pPlayer->Start();C#应该怎么实时C++例子的那段代码?求高手指点
特别是C++代码中 pPlayer = CPlaybackEngine::getInstance();在C#中应该怎么写?

解决方案 »

  1.   

    CPlaybackEngine* pPlayer = CPlaybackEngine::getInstance();C++中用getInstance()单例搞出了pPlayer ,然后通过pPlayer调用里面的方法,在C#中不知道这里应该怎么写了。直接调用导出的方法又老报尝试读写了受保护的内存这个错,。。
      

  2.   

    pPlayer 为CPlaybackEngine*类型,如果你作为IntPtr来操作,肯定是不行的,因为在C#里面不会支持CPlaybackEngine类型的存在。我建议在C里面做一个导出类,类函数名称,参数列表都和CPlaybackEngine的一样,再分别调用CPlaybackEngine里面的函数。
      

  3.   

    楼主的这个dll是VC写给VC自己用的吧,标准Dll库里面应该只有函数的。
      

  4.   

    直接调用dll里的函数就行呀,怎么还要实现呀?
      

  5.   

    他的dll里面的函数是一个单利模式的函数。
      

  6.   

    export class是MFC的特殊用法。C#的Platform invoke不支持调用exported class。只支持标准的export的函数。
      

  7.   

    直接调用dll里的函数,会出现“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”C++中CPlaybackEngine* pPlayer = CPlaybackEngine::getInstance();
    实例化后可以用pPlayer ,但是在C#中只能得到一个IntPtr,在接下来 pPlayer->SetMode(MP_MODE_SERV_PROXY);又不能把这个IntPtr作为参数输入。不知道应该怎么使用了?
      

  8.   

    [DllImport( "yourdll.dll ",EntryPoint= "yourFunction")] 
    public   static   extern   int   yourFunction();