Jump to content

Can I use a self-defined ".dll" file in the engine ?


Recommended Posts

Posted

Coucou everyone,


I have a problem, I added a new class and one function of this class calls a function from a ".dll" file.

I the game, I didn't create any instance of this class. And I just run the game, It got crashed...why ?

  • 3 weeks later...
Posted

An example - I wrote a .dll wrapper for Microsoft Speech SDK 11 and here's how I got it into Torque:

//TxtLib.h
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the TXTLIB_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// TXTLIB_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef TXTLIB_EXPORTS
#define TXTLIB_API __declspec(dllexport)
#include 
#include 
#include 
#include 
#include 
#include 
#else
#define TXTLIB_API __declspec(dllimport)
#include 
#endif
 
//// This class is exported from the TxtLib.dll
//class TXTLIB_API CTxtLib {
//public:
//	CTxtLib(void);
//	// TODO: add your methods here.
//};
//
//extern TXTLIB_API int nTxtLib;
//
//TXTLIB_API int fnTxtLib(void);
 
class TXTLIB_API CSpeechSynthesizer
{
private:
#ifdef TXTLIB_EXPORTS
	CComPtr cpIEnum;
	CComPtr cpToken;
	CComPtr cpVoice;
	bool m_initialized;
#endif
public:
	CSpeechSynthesizer();
	~CSpeechSynthesizer();
 
	bool IsInitialized();
 
	void Initialize();
 
	void SpeakText(const char* text, bool async);
 
	void SetVoice(std::string* name);
 
	std::list* GetAvailableVoices();
};
//SpeechSynthesizer.cpp
#include "console/console.h"
#include "console/engineAPI.h"
 
#include 
#include 
#include 
#include "TxtLib.h"
 
static bool ttsInitialized = false;
static CSpeechSynthesizer* synth = NULL;
 
bool InitTTS()
{
	std::wstring* dllName = new std::wstring(L".\\TxtLib.dll");
	HMODULE txtLib = LoadLibraryW(dllName->c_str()); // load the desired DLL
	if (!txtLib)
		return false;
	synth = new CSpeechSynthesizer();
	return true;
}
 
DefineEngineFunction(ttsCreateDevice, bool, ( ), ,
	"Try to create a new text-to-speech device.\n"
	"@ingroup SFX")
{
	ttsInitialized = InitTTS();
	if (ttsInitialized)
		synth->Initialize();
	return ttsInitialized;
}
 
DefineEngineFunction(ttsSpeak, void, (const char* text, bool async), ("", false) ,
	"Speak the text.\n")
{
	if (ttsInitialized)
	{
		synth->SpeakText(text, async);
	}
}
 
DefineEngineFunction(ttsIsInitialized, bool, (), ,
	"Try to create a new text-to-speech device.\n"
	"@ingroup SFX")
{
	if (ttsInitialized)
		return synth->IsInitialized();
	else
		return false;
}
// use in T3D:
function btnSpeak::onClick()
{
    if(txtSpeechText.text !$= "")
    {
        if(!ttsIsInitialized())
            ttsCreateDevice();
 
        if(ttsIsInitialized())
            ttsSpeak(txtSpeechText.getText(), true);
    }
}

And it speaks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...