Instructor
24th September 2005 10:58 UTC
Problem with C++ class in plugin
I have no errors when compiling:
...
TiXmlDocument doc;
extern "C" void __declspec(dllexport) LoadFile(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop)
{
...
if (!doc.LoadFile(szBuf))
...
}
But it crash when calling "doc.LoadFile(szBuf)".
If I write like this:
...
extern "C" void __declspec(dllexport) LoadFile(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop)
{
...
TiXmlDocument doc;
if (!doc.LoadFile(szBuf))
...
}
all working fine, but "TiXmlDocument doc" need to be global for other functions.
When I write console application no errors were occupied:
...
TiXmlDocument doc;
void loadit();
void parseit();
void saveit();
void main()
{
loadit();
parseit();
saveit();
}
void loadit()
{
...
if ( !doc.LoadFile(szBuf) )
...
}
Any suggestions?
kichik
24th September 2005 11:16 UTC
Use /NOUNLOAD or give the user a handle. The global is destroyed when the DLL is unloaded.
Instructor
24th September 2005 11:35 UTC
I use /NOUNLOAD, but it is unimportant, because it is crash after first call "xml::LoadFile":
Section
xml::LoadFile /NOUNLOAD "demotest.xml" .r0
xml::Parse /NOUNLOAD .r0
xml::SaveFile .r0
SectionEnd
kichik
24th September 2005 11:43 UTC
Then something else is probably happening inside xml::LoadFile. Not much can be said without more information.
Instructor
24th September 2005 13:59 UTC
Minimal variant of the strange error:
#include <windows.h>
#include "tinyxml.h"
typedef struct _stack_t {
struct _stack_t *next;
char text[1024];
} stack_t;
stack_t **g_stacktop;
TiXmlDocument doc;
extern "C" void __declspec(dllexport) Load(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop)
{
doc.LoadFile("demotest.xml");
}
BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}
Without error:
#include <windows.h>
#include "tinyxml.h"
typedef struct _stack_t {
struct _stack_t *next;
char text[1024];
} stack_t;
stack_t **g_stacktop;
extern "C" void __declspec(dllexport) Load(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop)
{
TiXmlDocument doc;
doc.LoadFile("demotest.xml");
}
BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}
kichik
24th September 2005 15:02 UTC
You need to manually initialize doc. Without libc, constructors for global variables aren't called.
Instructor
24th September 2005 15:48 UTC
I got it, thanks!
Instructor
24th September 2005 18:28 UTC
I had a little played with compiler options and here that have found out. I have erased entry point (/entry:"DllMain"->"") and no errors were occupied!