我是用java做开发的,现在想通过dll调用dcom,但是vc不熟,不知道在dll中怎样调用docm?我急用!请各位大哥帮帮忙!有例子最好。我按例子调用下面这个函数,为何总是返回false?
// Initialize COM security for DCOM services.
// Returns true if successful.
BOOL CWMIApp::InitSecurity()
{
// Adjust the security to allow client impersonation.
HRESULT hres = CoInitializeSecurity
(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_NONE,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, 0, 0); return (SUCCEEDED(hres));
}
// Initialize COM security for DCOM services.
// Returns true if successful.
BOOL CWMIApp::InitSecurity()
{
// Adjust the security to allow client impersonation.
HRESULT hres = CoInitializeSecurity
(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_NONE,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, 0, 0); return (SUCCEEDED(hres));
}
然后在调用DLL的程序中进行安全性设置
BOOL CWMIApp::Initialize()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(_T("Failed to initialize OLE"));
return FALSE;
}
if (!InitSecurity())
{
AfxMessageBox(_T("Failed to fix security"));
return FALSE;
}
AfxMessageBox(_T("WMI Initialize succeeded"));
return TRUE;
}
不知行不?