// if(riid==NULL)riid=&IID_IUnknown
int _stdcall CrComObj(
LPCSTR lpDll,
CLSID *rclsid,
IID *riid,
LPVOID * ppv)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
int rtn=0;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(lpDll);
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd =(MYPROC)GetProcAddress(hinstLib, "DllGetClassObject");
// If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (ProcAdd != NULL))
{
if(rclsid==NULL)
{
FreeLibrary(hinstLib);
return 0;
}
if(riid==NULL)
riid=(IID *)&IID_IUnknown;
IClassFactory *pIf;
pIf=NULL;
if(ProcAdd(*rclsid,IID_IClassFactory,(void **)&pIf)==S_OK && pIf!=NULL)
{
if(pIf->CreateInstance(NULL,*riid,ppv)==S_OK)
rtn=(int)hinstLib;
pIf->Release();
pIf=NULL;
}
}
// Free the DLL module.
if(!rtn)fFreeResult = FreeLibrary(hinstLib);
}
return rtn;
}
// if strriid==NULL, use IID_IUnknown;
int _stdcall CrComObj2(
LPCSTR lpDll,
LPCSTR strrclsid,
LPCSTR strriid,
LPVOID * ppv )
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
int rtn=0;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(lpDll);
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd =(MYPROC)GetProcAddress(hi