[C++] 纯文本查看 复制代码
#import "lw.dll" no_namespace
#import "dm3.1.dll" no_namespace
//int main(int argc, char* argv[])
//{
// return 0;
//}
#include "Debug\lw.tlh"
#include "Debug\dm3.1.tlh"
#include <iostream>
using namespace std;
Idmsoft* Dm; //大漠插件
Idmsoft* GetDmObject();
Ilwsoft* Lw; //大漠插件
Ilwsoft* GetLwObject();
int main(int argc, char* argv[])
{
Dm = GetDmObject();
cout << (char*)Dm->Ver() << endl;
Lw = GetLwObject();
cout<<(char*)Lw->ver() <<endl;
return 0;
}
//创建lw对象
Ilwsoft* GetLwObject()
{
Ilwsoft* m_lw = NULL;
bool m_bInit = false;
//直接加载dll创建对象,避免进行注册文件
typedef HRESULT(_stdcall* pfnGCO)(REFCLSID, REFIID, void**);
pfnGCO fnGCO = NULL;
HINSTANCE hdllInst = LoadLibrary(L"lw.dll");
fnGCO = (pfnGCO)GetProcAddress(hdllInst, "DllGetClassObject");
if (fnGCO != 0)
{
IClassFactory* pcf = NULL;
HRESULT hr = (fnGCO)(__uuidof(lwsoft), IID_IClassFactory, (void**)&pcf);
if (SUCCEEDED(hr) && (pcf != NULL))
{
hr = pcf->CreateInstance(NULL, __uuidof(Ilwsoft), (void**)&m_lw);
if ((SUCCEEDED(hr) && (m_lw != NULL)) == FALSE)
return NULL;
}
pcf->Release();
m_bInit = true;
}
else
m_bInit = false;
return m_lw;
}
//创建大漠对象
Idmsoft* GetDmObject()
{
Idmsoft* m_dm = NULL;
bool m_bInit = false;
//直接加载dll创建对象,避免进行注册文件
typedef HRESULT(_stdcall* pfnGCO)(REFCLSID, REFIID, void**);
pfnGCO fnGCO = NULL;
HINSTANCE hdllInst = LoadLibrary(L"dm3.1.dll");
fnGCO = (pfnGCO)GetProcAddress(hdllInst, "DllGetClassObject");
if (fnGCO != 0)
{
IClassFactory* pcf = NULL;
HRESULT hr = (fnGCO)(__uuidof(dmsoft), IID_IClassFactory, (void**)&pcf);
if (SUCCEEDED(hr) && (pcf != NULL))
{
hr = pcf->CreateInstance(NULL, __uuidof(Idmsoft), (void**)&m_dm);
if ((SUCCEEDED(hr) && (m_dm != NULL)) == FALSE)
return NULL;
}
pcf->Release();
m_bInit = true;
}
else
m_bInit = false;
return m_dm;
}
代码如上,大漠调用正常,调用乐玩就会在加载dll哪里报错,这是什么原因? |