Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

zackriggle

Exporting template functions with a DLL

This topic is 5528 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright, I know that this *should* compile and give me a .dll and .lib file, but all I get is a .dll file. Please tell me why... The header file
////////////////////////////

// CMUTEX.H

////////////////////////////

#pragma once

#ifdef CMUTEX_EXPORTS
#define MUTEX_DLL __declspec(dllexport)
#else
#define MUTEX_DLL __declspec(dllimport)
#endif

#include <windows.h>
#include <fstream.h>

template <class T>
class cMutex
{
public:
	//## Constructor

	MUTEX_DLL cMutex();
	MUTEX_DLL ~cMutex();

	//## Check to see if the mutex is locked

	MUTEX_DLL bool	IsLocked();

	//## Lock the mutex

	MUTEX_DLL T*		Lock();

	//## Unlock the mutex

	MUTEX_DLL bool	Unlock();

	//## Get a copy of the data ( if you cannot actually edit the real value )

	MUTEX_DLL T*		GetCopy();

	//## Retreive the pointer

	MUTEX_DLL T*		GetPtr();

	//## Set the pointer

	MUTEX_DLL bool	SetPtr(T*);

	//## Set true/false for de-allocation on the destructor

	MUTEX_DLL bool	SetDeallocate(bool);


private: 
	//## Pointer to the protected data

	T		*m_pData;

	//## Number of bytes allocated (for creating copies of the data)

	WORD	m_nBytesAllocated;

	//## ID of the thread that called Lock().  Only that same

	//## thread can unlock the mutex.

	DWORD	m_dwCallerID;

	//## Do we want to deallocate the memory on ~cMutex() ???

	bool	m_bDeallocateOnDestructor;
};
Here is the .cpp file:
////////////////////////////////

// CMUTEX.CPP

////////////////////////////////

#define CMUTEX_EXPORTS
#include "cmutex.h"

template<class T>
MUTEX_DLL cMutex<T>::cMutex()
{
	// Initialize the values

	m_bDeallocateOnDestructor = true;
	m_dwCallerID = 0;
	m_nBytesAllocated = 0;
	m_pData = NULL;
};
================== My (soon-to-be) Cherished Cookie of Appreciation: -- MattB - for WinSock advice -- -- Sneftel - for telling me how 'extern' works -- [edited by - zackriggle on June 2, 2003 8:03:51 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hey!

What compiler are you using?
If I'm not mistaken there is a checkbox to turn of lib generated files so you only end up with a dll.

One funny thing that still beats me thought is that I once had to add /implib:"libname.lib" in the project settings under the link tab in VC++
Must have done something crazy...

BTW:
I can't tell what's supposed to be right and wrong but I tend to add in your case the MUTEX_DLL in the class defenition instead of before every function.

class MUTEX_DLL cMutex
{
// more code...
};

The Lord says He can get me out of this mess, but He's pretty sure you're fucked.
- Stephen (Braveheart)


[edited by - Willbo on June 3, 2003 8:52:33 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!