64-bit client call to 32-bit COM/ATL server EXE fails

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
The following unmanaged C++ client program works when compiled in 32-bit to match the server but fails when compiled in 64-bit mode:<br/><br/>
<pre>// Client.cpp
//
// Client calls Server - 64-bit App to 32-bit Service
//
#include <iostream>
#include <iomanip>
using namespace std;

#include <objbase.h>
#include "..AAServerAAServer_i.h"

IAAGetSet* pGetSet;

int main()
{
cout << "tAClient built in " << 8*sizeof(int*) << "-bit mode." << endl << endl;

HRESULT hr = 0;

hr = CoInitialize(NULL);
if (FAILED(hr))
{
cout << "CoInitialize failed: " << hex << hr << endl;
exit(0);
}

hr = CoCreateInstance(CLSID_AAServe, NULL, CLSCTX_LOCAL_SERVER, IID_IAAGetSet, (LPVOID*) &pGetSet); // Surrogate fails

if (FAILED(hr))
{
cout << "CoCreateInstance failed: " << hex << hr << endl;
exit(0);
}

hr = pGetSet->Set(1234);
if (FAILED(hr))
{
cout << "Set failed: " << hex << hr << endl;
pGetSet->Release();
exit(0);
}

long a = 0;

hr = pGetSet->Get(&a);
if (FAILED(hr))
{
cout << "Get failed: " << hex << hr << endl;
exit(0);
}

cout << "Value: " << a << endl;

pGetSet->Release();

CoUninitialize();

return 0;
}

[/code]
The following code is the C++ server EXE. The goal is to have 64-bit code call via COM/ATL a 32-bit server that calls a 32-bit DLL. These are minimal test modules to bridge the 64-bit to 32-bit gap through out-of-process calls.<br/><br/>
<pre>// AAServer.cpp : Implementation of WinMain


#include "stdafx.h"
#include "resource.h"
#include "AAServer_i.h"


class CAAServerModule : public CAtlExeModuleT< CAAServerModule >
{
public :
DECLARE_LIBID(LIBID_AAServerLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_AASERVER, "{7E7AFADF-7878-4BCD-8A15-F9ECD4C2F9E6}")
};

CAAServerModule _AtlModule;



//
extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/,
LPTSTR /*lpCmdLine*/, int nShowCmd)
{
return _AtlModule.WinMain(nShowCmd);
}

// AAServer.cpp : Implementation of CAAServer

#include "stdafx.h"
#include "AAServer.h"


// CAAServer


STDMETHODIMP CAAServer::Set(LONG a)
{
val = a;

return S_OK;
}

STDMETHODIMP CAAServer::Get(LONG* a)
{
*a = val;

return S_OK;
}
[/code]
<br/>The error code returned by the call to CoCreateInstance is 80040154 Class not registered.<br/><br/>OLE/COM Object Viewer shows:<br/><br/>AAServe Class<br/>CLSID =<br/>  {4CD59D98-6F6F-45E9-9B9A-04F49B17DF48}<br/>   {4CD59D98-6F6F-45E9-9B9A-04F49B17DF48} [AppID] = {4CD59D98-6F6F-45E9-9B9A-04F49B17DF48}<br/><br/>    LocalServer32 = "c:Edx64AAServerDebugAAServer.exe"<br/>    ProgID = AAServer.ASAServ.1<br/>    TypeLib = {EF9BF824-30CC-4C03-4C03-9E8C-A59EF4F36347}<br/>    VersionIndependentProgID = AAServer.AAServe<br/>AppID<br/>  {4CD59D98-6F6F-45E9-9B9A-04F49B17DF48} [<no name>] = AAServe Class<br/>  {4CD59D98-6F6F-45E9-9B9A-04F49B17DF48} [DllSurrogate] =<br/>AAServer.AAServer.1 = AAServe Class<br/>  CLSID = {4CD59D98-6F6F-45E9-9B9A-04F49B17DF48}<br/>TypeLib =<br/>  {EF9BF824-30CC-4C03-9E8C-A59EF4F36347}<br/>    1.0 = AAServer 1.0 Type Library<br/>      0<br/>        win32 = c:Edxc64AAServerDebugAAServer.exe<br/>      FLAGS = 0<br/>      HELPDIR = c:Edx64AAServerDebug<br/><br/>This appears to be a problem in the Registry search. The 32-bit server must be properly registered because the 32-bit client finds it and the program works. The 64-bit compile mode for the server does not find the 32-bit server EXE.<br/><br/>The Forum Category list and specific Forums do not match my issue very well. Is there another Technical Forum list that would be more appropriate?<br/><br/>Thanks,<br/><br/>Ed S<br/>

View the full article
 
Back
Top