Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exposing functions with STDAPI

Status
Not open for further replies.

Milby7

Programmer
Dec 5, 2003
67
0
0
GB
Hi!
I'm trying to learn how to write com component servers (dll's) using plain c++ (no mfc, or atl) & am having trouble exposing the necessary functions - DllRegisterServer, DllUnregisterServer, DllCanUnloadNow, & DllGetClassObject prefixing each with STDAPI. I read somewhere on MSDN that you have to add a preprocessor directive or a compiler switch for STDAPI to expose functions, but it didn't actually say what they are. I'd really rather not use a .def file, but @ the moment I'm REALLY stuck without one!
If anyone could help I'd really appreciate it! ::)
 
Code:
MyComApp.h
**********


#include "resource.h"       // main symbols

/////////////////////////////////////////////////////////////////////////////
// MyCOMApp : See IMCOM.cpp for implementation.

class MyCOMApp : public COleControlModule
{
public:
	BOOL InitInstance();
	int ExitInstance();
};

extern const GUID CDECL _tlid;
extern const WORD _wVerMajor;
extern const WORD _wVerMinor;

MyCOMApp.cpp
************

// IMCOM.cpp : Implementation of MyCOMApp and DLL registration.

#include "stdafx.h"
#include "MyCOMApp.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


MyCOMApp NEAR theApp;

const GUID CDECL BASED_CODE _tlid =
		{ 0xf9cbace3, 0x5969, 0x11d4, { 0x82, 0x8a, 0, 0xc0, 0xa8, 0x47, 0xd5, 0x28 } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;


////////////////////////////////////////////////////////////////////////////
// MyCOMApp::InitInstance - DLL initialization

BOOL MyCOMApp::InitInstance()
{
	BOOL bInit = COleControlModule::InitInstance();

	if (bInit)
	{
		// TODO: Add your own module initialization code here.
	}

	return bInit;
}


////////////////////////////////////////////////////////////////////////////
// MyCOMApp::ExitInstance - DLL termination

int MyCOMApp::ExitInstance()
{
	// TODO: Add your own module termination code here.

	return COleControlModule::ExitInstance();
}


/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry

STDAPI DllRegisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
		return ResultFromScode(SELFREG_E_CLASS);

	return NOERROR;
}


/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
		return ResultFromScode(SELFREG_E_CLASS);

	return NOERROR;
}
-obislavu-
 
Hi obislavu!
Thanks for your help, but I can't seem to make sense of why my functions aren't being made available to calling exe's. I've built a debug version of my test project but when I try to register it with regsvr32.exe I get the following message:
"c:\dev\dll_test\Debug\dll_test.dll was loaded, but the DllRegisterServer entry point was not found.
This file can not be registered."
As far as I can see, my implementation of DllRegisterServer should work. Am I missing something?
Code:
// main.cpp

#define _CTEST_EXTERN_  // define external declarations in ctest.h

#include <windows.h>
#include <cregister.h>	// com registration class

#include &quot;ctest.h&quot;

STDAPI DllCanUnloadNow()
{
        // source code
}

STDAPI DllGetClassObject(const CLSID& clsid, const IID& iid, void** ppv)
{
	// source code
}

STDAPI DllRegisterServer()
{
	// source code
}

STDAPI DllUnregisterServer()
{
	// source code
}

BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, void* lpReserved)
{
	// source code 
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top