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

Expanding and utilizing the engine via C++.
3 posts Page 1 of 1
baileyange
Posts: 5
Joined: Mon Apr 27, 2015 10:35 am
by baileyange » Thu Apr 30, 2015 7:17 am
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 ?
rlranft
Posts: 298
Joined: Thu Feb 05, 2015 3:11 pm
 
by rlranft » Thu Apr 30, 2015 10:53 pm
Error log? Anything? Is your path to the dll correct?
rlranft
Posts: 298
Joined: Thu Feb 05, 2015 3:11 pm
 
by rlranft » Wed May 20, 2015 3:07 pm
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 <Windows.h>
#include <sapi.h>
#include <sperror.h>
#include <sphelper.h>
#include <string>
#include <list>
#else
#define TXTLIB_API __declspec(dllimport)
#include <tchar.h>
#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<IEnumSpObjectTokens> cpIEnum;
	CComPtr<ISpObjectToken> cpToken;
	CComPtr<ISpVoice> 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<std::string*>* GetAvailableVoices();
};
//SpeechSynthesizer.cpp
#include "console/console.h"
#include "console/engineAPI.h"

#include <windows.h>
#include <string>
#include <list>
#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.
3 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest