1

I have created a COM dll in Microsoft Visual Basic 2008. I am trying to call this dll from a C++ project. In the C++ I used "#import U:\path...\MyComDll.tlb" I then used the following code to the DisplayMessage() method.

FB::variant CmdAccessAPI::filePSV(std::string file)
{

CoInitialize(NULL);
try
{
    _MyComClassPtr spIMyComClass;
    HRESULT hr = spIMyComClass.CreateInstance(__uuidof(_MyComClass));
    if (FAILED(hr)) throw _com_error(hr);

    spIMyComClass->DisplayMessage();
}
    catch (std::exception& e)
{
    CString strMsg(e.what());
    MessageBox(NULL, strMsg, L"Error", MB_OK);
}
catch (_com_error& e)
{
    CString strMsg;
    strMsg = (TCHAR*) e.Description();
    strMsg += _T("\n");
    strMsg += (TCHAR*) e.ErrorMessage();
    MessageBox(NULL, strMsg, L"COM Error", MB_OK);
}
CoUninitialize();
return "test";
}

When I call this function I get a Class Not Registered error. I have tried to register the dll using regsvr32 and I get the message "MyComDll.dll was loaded, but the DLLREgeisterServer entry point was not found. This file can not be registered."

How do I register the class and get this to work?

2
  • 1
    .NET assemblies must be registered with Regasm.exe. On your dev machine, use the /codebase option so you don't have to put it in the GAC. Ignore the warning you get. Commented Jul 28, 2011 at 22:31
  • Wish I could accept this as the answer. Commented Jul 29, 2011 at 15:23

5 Answers 5

1

Try registering it using admin privileges, Right click on the Command prompt and choose run as administrator, and give the systems 32 path. Then use regsvr32 xyz.dll

Sign up to request clarification or add additional context in comments.

Comments

0

If you can't register it, there are two possibilities

  1. You are missing a dependent library. Download dependency walker and see what's missing. Some of the ones that are marked missing are red herrings (ieshims.dll for example), but one of them may be yours

  2. Something went way off the rails in your COM setup. You can debug your dll as its being registered and dig into the ATL code where its failing.

1 Comment

Because he is seeing the "DLLREgeisterServer entry point was not found" message, it is not going to be #1 (would not be able to load the dll without the dependencies). But #1 is something to watch out for in other cases.
0

You need to use regsvr32 to register the DLL, as you suspect.

However, the error its giving suggests that either the DLL doesn't have the stub included (and so cannot register itself) or you're trying to register the library, not the stub.

Make sure your VS project and the code is set up to include the proxy/stub functions in your DLL, or make sure you register the proxy DLL.

2 Comments

"Make sure your VS project and the code is set up to include the proxy/stub functions in your DLL, or make sure you register the proxy DLL." - How do I do this?
If this is your issue, it's in the project settings when you created it. I'm not entirely sure how to add that in later, Google may know; if you're using ATL it may be possible, if not, it'll be a right pain.
0
**include the below code** and export these functions with .def file

wchar_t *convertCharArrayToLPCWSTR(const char* charArray)
{
    wchar_t* wString=new wchar_t[4096];
    MultiByteToWideChar(CP_ACP, 0, charArray, -1, wString, 4096);
    return wString;
}

BOOL   Register( HKEY mainKey,const char *subKey,LPCTSTR val_name, DWORD dwType,char * chardata,DWORD dwDataSize)
{
    HKEY hk;
    if (ERROR_SUCCESS != RegCreateKey(mainKey,convertCharArrayToLPCWSTR(subKey),&hk) )
        return FALSE;
    LPCTSTR data=convertCharArrayToLPCWSTR(chardata);
    if (ERROR_SUCCESS != RegSetValueEx(hk,val_name,0,dwType,(CONST BYTE *)data,2*dwDataSize)) 
        return FALSE;
    if (ERROR_SUCCESS != RegCloseKey(hk))   
        return FALSE;
    return TRUE;
}

HRESULT  __stdcall DllRegisterServer(void)
{

    WCHAR *lpwszClsid;
    char szBuff[MAX_PATH]="new multiplication Algorithm";
    char szClsid[MAX_PATH]="", szInproc[MAX_PATH]="",szProgId[MAX_PATH];
    char szDescriptionVal[256]="";
    StringFromCLSID(CLSID_MultiplicationObject,&lpwszClsid);
    sprintf(szClsid,"%S",lpwszClsid);
    sprintf(szInproc,"%s\\%s\\%s","clsid",szClsid,"InprocServer32");
    sprintf(szProgId,"%s\\%s\\%s","clsid",szClsid,"ProgId");
    sprintf(szDescriptionVal,"%s\\%s","clsid",szClsid);
    Register (HKEY_CLASSES_ROOT,szDescriptionVal,NULL,REG_SZ,szBuff,strlen(szBuff));
    //InprocServer32
    GetModuleFileNameA(g_hModule,szBuff,sizeof(szBuff));
    Register (HKEY_CLASSES_ROOT,szInproc,NULL,REG_SZ,szBuff,strlen((szBuff)));
    //ProgId
    strcpy(szBuff,multiplicationObjProgId);
    Register (HKEY_CLASSES_ROOT,szProgId,NULL,REG_SZ,szBuff,strlen(szBuff));
    return 1;
}

HRESULT  __stdcall DllUnregisterServer(void)
{
    WCHAR *lpwszClsid;
    char szBuff[MAX_PATH]="new multiplication Algorithm";
    char szClsid[MAX_PATH]="", szInproc[MAX_PATH]="",szProgId[MAX_PATH];
    char szDescriptionVal[256]="";
    StringFromCLSID(CLSID_MultiplicationObject,&lpwszClsid);
    sprintf(szClsid,"%S",lpwszClsid);
    sprintf(szInproc,"%s\\%s\\%s","clsid",szClsid,"InprocServer32");
    sprintf(szProgId,"%s\\%s\\%s","clsid",szClsid,"ProgId");
    sprintf(szDescriptionVal,"%s\\%s","clsid",szClsid);
    RegDeleteKey(HKEY_CLASSES_ROOT,convertCharArrayToLPCWSTR(szInproc));
    RegDeleteKey(HKEY_CLASSES_ROOT,convertCharArrayToLPCWSTR(szProgId));
    RegDeleteKey(HKEY_CLASSES_ROOT,convertCharArrayToLPCWSTR(szDescriptionVal));
    return 1;

}

Comments

0

This kind of dependency problem can happen when there is a mismatch in vendor architecture.

For example, you may have registered the 32bit DLL but your program is 64bit or vice-versa.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.