想使用一个组件的方法和属性,但组件并没有注册,写了以下的代码:
typedef LONG (*MYPROC)(REFCLSID,REFIID,LPVOID*); 
MYPROC myproc;
HMODULE hin=LoadLibrary("qmail.dll");
myproc=(MYPROC)GetProcAddress(hin,"DllGetClassObject");
IDispatch* qupload;
struct __declspec(uuid("E2F1F220-89BC-4E36-9E19-60383691E69E")) A;
struct __declspec(uuid("D07B9368-88D2-4949-A180-0D95CC2D2F4A")) B;
myproc(__uuidof(A),__uuidof(B),(LPVOID*)&qupload);
现在是在运行时,跳出一个框子:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.该组件相关的信息如下:
// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: Qmail.dll[
  uuid(F8DF570B-B87D-4EB4-B10E-55D439409B96),
  version(1.0),
  helpstring("Qmail 1.0 Type Library"),
  custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 83951780),
  custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1035042075)]
library QMAILLib
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("STDOLE2.TLB");    // Forward declare all types defined in this typelib
    interface INewMail;
    interface IInbox;
    interface IRegister;
    interface IUpload;    [
      uuid(9FE9EC1A-6391-46A7-83E9-023BEFAC73A6),
      helpstring("NewMail Class")
    ]
    coclass NewMail {
        [default] interface INewMail;
    };    [
      odl,
      uuid(1CFFC04A-3342-46F3-BF5A-787671C362FB),
      helpstring("INewMail Interface"),
      dual,
      oleautomation
    ]
    interface INewMail : IDispatch {
        [id(0x00000001), propput, helpstring("property sender")]
        HRESULT sender([in] VARIANT* rhs);
        [id(0x00000002), propput, helpstring("property smtpsvr")]
        HRESULT smtpsvr([in] VARIANT* rhs);
        [id(0x00000003), propput, helpstring("property receiver")]
        HRESULT receiver([in] VARIANT* rhs);
        [id(0x00000004), propput, helpstring("property auth")]
        HRESULT auth([in] VARIANT_BOOL rhs);
        [id(0x00000005), propput, helpstring("property user")]
        HRESULT user([in] VARIANT* rhs);
        [id(0x00000006), propput, helpstring("property pass")]
        HRESULT pass([in] VARIANT* rhs);
        [id(0x00000007), propput, helpstring("property body")]
        HRESULT body([in] VARIANT* rhs);
        [id(0x00000008), propput, helpstring("property subject")]
        HRESULT subject([in] VARIANT* rhs);
        [id(0x00000009), propget, helpstring("property ErrString")]
        HRESULT ErrString([out, retval] BSTR* pVal);
        [id(0x0000000a), helpstring("method AddAttach")]
        HRESULT AddAttach(BSTR filename);
        [id(0x0000000b), helpstring("method Send")]
        HRESULT Send();
        [id(0x0000000c), propget, helpstring("property ErrCode")]
        HRESULT ErrCode([out, retval] VARIANT_BOOL* pVal);
        [id(0x0000000d), propput, helpstring("property SendAsHTML")]
        HRESULT SendAsHTML([in] VARIANT_BOOL rhs);
    };    [
      uuid(AA847F77-16A8-4DAB-BAEA-CB19D77D55C0),
      helpstring("Inbox Class")
    ]
    coclass Inbox {
        [default] interface IInbox;
    };    [
      odl,
      uuid(C9C19C6B-16D4-4890-8EB0-882904599D9B),
      helpstring("IInbox Interface"),
      dual,
      oleautomation
    ]
    interface IInbox : IDispatch {
        [id(0x00000001), helpstring("method LogIn")]
        HRESULT LogIn(
                        BSTR popsvr, 
                        BSTR user, 
                        BSTR pass);
        [id(0x00000002), propget, helpstring("property count")]
        HRESULT count([out, retval] short* pVal);
        [id(0x00000003), propget, helpstring("property ErrCode")]
        HRESULT ErrCode([out, retval] VARIANT_BOOL* pVal);
        [id(0x00000004), propget, helpstring("property ErrString")]
        HRESULT ErrString([out, retval] BSTR* pVal);
        [id(0x00000005), propget, helpstring("property from")]
        HRESULT from(
                        int nIndex, 
                        [out, retval] BSTR* pVal);
        [id(0x00000006), propget, helpstring("property subject")]
        HRESULT subject(
                        int nIndex, 
                        [out, retval] BSTR* pVal);
        [id(0x00000007), propget, helpstring("property date")]
        HRESULT date(
                        int nIndex, 
                        [out, retval] BSTR* pVal);
        [id(0x00000008), propget, helpstring("property length")]
        HRESULT length(
                        int nIndex, 
                        [out, retval] long* pVal);
        [id(0x00000009), helpstring("method SaveAs")]
        HRESULT SaveAs(
                        int nIndex, 
                        BSTR filename);
        [id(0x0000000a), helpstring("method dele")]
        HRESULT dele(int nIndex);
        [id(0x0000000b), helpstring("method LogOut")]
        HRESULT LogOut();
    };    [
      uuid(23F8A6E5-3234-4703-A7A0-BC84D89DE460),
      helpstring("Register Class")
    ]
    coclass Register {
        [default] interface IRegister;
    };    [
      odl,
      uuid(894DD15B-D42A-42F7-BEC4-FAA1511DE8CE),
      helpstring("IRegister Interface"),
      dual,
      oleautomation
    ]
    interface IRegister : IDispatch {
        [id(0x00000001), helpstring("method regis")]
        HRESULT regis(unsigned long zcm);
        [id(0x00000002), propget, helpstring("property IsRegis")]
        HRESULT IsRegis([out, retval] VARIANT_BOOL* pVal);
        [id(0x00000003), propget, helpstring("property srlno")]
        HRESULT srlno([out, retval] double* pVal);
    };    [
      uuid(E2F1F220-89BC-4E36-9E19-60383691E69E),
      helpstring("Upload Class")
    ]
    coclass Upload {
        [default] interface IUpload;
    };    [
      odl,
      uuid(D07B9368-88D2-4949-A180-0D95CC2D2F4A),
      helpstring("IUpload Interface"),
      dual,
      oleautomation
    ]
    interface IUpload : IDispatch {
        [id(0x00000001), helpstring("method init")]
        HRESULT init(VARIANT* data);
        [id(0x00000002), propget, helpstring("property filename")]
        HRESULT filename(
                        VARIANT* formdata, 
                        [out, retval] BSTR* pVal);
        [id(0x00000003), propget, helpstring("property value")]
        HRESULT value(
                        VARIANT* formdata, 
                        [out, retval] VARIANT* pVal);
        [id(0x00000004), helpstring("method SaveFile")]
        HRESULT SaveFile(
                        VARIANT* formdata, 
                        BSTR direc, 
                        [optional] VARIANT* filename);
        [id(0x00000005), helpstring("method DelFile")]
        HRESULT DelFile(VARIANT* formdata);
        [id(0x00000006), helpstring("method DelFileAll")]
        HRESULT DelFileAll();
        [id(0x00000007), propget, helpstring("property len")]
        HRESULT len(
                        VARIANT* formdata, 
                        [out, retval] long* pVal);
        [id(0x00000008), propget, helpstring("property Bvalue")]
        HRESULT Bvalue(
                        VARIANT* formdata, 
                        [out, retval] VARIANT_BOOL* pVal);
        [id(0x00000009), propget, helpstring("property CESHI")]
        HRESULT CESHI([out, retval] BSTR* pVal);
        [id(0x00000009), propput, helpstring("property CESHI")]
        HRESULT CESHI([in] BSTR pVal);
    };
};

解决方案 »

  1.   

    typedef HRESULT __stdcall DLLGETCLASSOBJECT(REFCLSID rclsid,REFIID   riid,void   **ppv);
      DLLGETCLASSOBJECT   *dllGetClassObject;
    dllGetClassObject = (DLLGETCLASSOBJECT*)GetProcAddress(hDll, "PAL_CoCreateInstance");
    you missed "__stdcall "
      

  2.   

    感谢masterz(MS MVP)
    我把程序做了如下改动:   CLSID clsID;
    USES_CONVERSION;
    CLSIDFromString(A2W("{E2F1F220-89BC-4E36-9E19-60383691E69E}"),&clsID);typedef LONG (WINAPI *MYPROC)(REFCLSID,REFIID,LPVOID*); 
    IDispatch* qupload;
    MYPROC myproc;
    HMODULE hin=LoadLibrary("qmail.dll");
    myproc=(MYPROC)GetProcAddress(hin,"DllGetClassObject");
    HRESULT hr= myproc(clsID,__uuidof(IDispatch),(void**)(&qupload));
    返回错误:E_NOINTERFACE
      

  3.   

    DllGetClassObject只能返回类厂指针!这样试试..  CLSID clsID;
    USES_CONVERSION;
    CLSIDFromString(A2W("{E2F1F220-89BC-4E36-9E19-60383691E69E}"),&clsID);typedef LONG (WINAPI *MYPROC)(REFCLSID,REFIID,LPVOID*);
    IClassFactory *pCF=NULL; 
    IDispatch* qupload;
    MYPROC myproc;
    HMODULE hin=LoadLibrary("qmail.dll");
    myproc=(MYPROC)GetProcAddress(hin,"DllGetClassObject");
    HRESULT hr= myproc(clsID,IID_IClassFactory ,(void**)(&pCF));
    hr=pCF->CreateInstance(NULL,IID_IDispatch,(void**)(&qupload));为什麽要返回IDispatch指针呢?
      

  4.   

    to:lwg7603(刑满释放人员) 
    我试过用IID_IClassFactory ,结果一样,找不到接口
      

  5.   

    那很可能是组件没注册了!你先调用DllRegisterServer试试~~~