PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Building for DLL use?

InexorableTash · 23 Nov 2005, 06:23 UTC
I finally decided to port my hobby project from GD3.01 to GD3.5 and ran into an issue.

If I build using the statically linked LIB everything is fine - but I want to build using the dynamically linked lib (LIB/DLL).

Here's what I'm seeing, with a repro for one of the samples:

* Copy the win32\Simple project
* Open it up in VS2003
* In the project properties, set Linker:General:Additional Library Directories to dll\vs2003-debug
* Copy the GapiDraw.DLL from that folder into the project folder
* Compile and run

The app runs fine until you exit

Unhandled exception at 0x7c901230 in simple.exe: User breakpoint.

The callstack is:

ntdll.dll!7c901230()
ntdll.dll!7c96c943()
ntdll.dll!7c96cd80()
ntdll.dll!7c960af8()
kernel32.dll!7c85e7af()
msvcr71d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x00a34f68) Line 1807 C
msvcr71d.dll!_free_dbg_lk(void * pUserData=0x00a34f68, int nBlockUse=1) Line 1132 + 0x9 C
msvcr71d.dll!_free_dbg(void * pUserData=0x00a34f68, int nBlockUse=1) Line 1070 + 0xd C
msvcr71d.dll!operator delete(void * pUserData=0x00a34f68) Line 54 + 0x10 C++
GapiDraw.dll!10005685()
> simple.exe!CMyApplication::~CMyApplication() Line 72 + 0x38 C++
simple.exe!CMyApplication::`scalar deleting destructor'() + 0x2b C++
simple.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * hPrevInst=0x00000000, char * pCmdLine=0x00141f23, int nCmdShow=1) Line 55 + 0x33 C++
simple.exe!WinMainCRTStartup() Line 251 + 0x30 C
kernel32.dll!7c816d4f()
ntdll.dll!7c915b4f()
kernel32.dll!7c8399f3()

In other words, it's puking in the delete operator of the first CGapiSurface it tries to tear down.

Are there additional steps needed to get the use of the DLL working? Did I miss the docs somewhere?
InexorableTash · 15 Feb 2006, 05:33 UTC
Bump - any ideas?
I am getting the same problem I guess. It is very easy to reproduce. Take the simple sample demo.

Change "Additional Library Directories" to use the DLL folder rather than LIB. Place the DLL with the exe. Run the app. When you attempt to exit the application it blows up on the delete for font.

Are we missing a preprocessor flag? What else is necessary to use the DLL rather than the static lib.

FYI, it doesn't matter when the delete is called. Within a function you can new a CGapiSurface and the try to delete it. It will bang straight away.

Slightly puzzled.
Strange, I have not experienced this issue with the debug version. Can you try to check your C++ settings for Runtime library and change that? I.e. if it's now "Multi-threaded Debug" then change it into "Multi-threaded Debug DLL" etc.. Try some changes and see what happens. I'll also investigate on my part.

Sincerely
Johan
Yes that is it Johan, Runtime was set to Multithreaded-Debug. :roll: Changing to Multithreaded-Debug DLL works fine. :D

Many Thanks.
Great! I'll add it to the FAQ!

//Johan
InexorableTash · 01 Mar 2006, 05:35 UTC
Confirmed, that did it, both with the sample and with my XP and PocketPC builds of my hobby project.

Thanks, Johan!
InexorableTash · 15 May 2006, 05:34 UTC
For posterity, note that when you switch to VS2005 you run into a little bit of fun: Microsoft's Visual C++ Runtime (MSVCRT) was updated in VS8, so it is not longer "automagically present" on devices.

See http://msdn2.microsoft.com/en-US/library/c5fc53wa.aspx for instructions on how to deploy the MSVCRT80[d].DLL to your device when building in VS2005.[/url]
I am using VS2003.net for C++ and have the same problem.

My project setting is already in /MDd

ntdll.dll!_DbgBreakPoint@0()
ntdll.dll!_RtlpBreakPointHeap@4() + 0x28
ntdll.dll!_RtlpValidateHeapEntry@12() + 0x113
ntdll.dll!_RtlValidateHeap@12() + 0xe0
kernel32.dll!7c85e9cf()
> msvcr71d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x011b4f88) Line 1807 C
msvcr71d.dll!_free_dbg_lk(void * pUserData=0x011b4f88, int nBlockUse=1) Line 1132 + 0x9 C
msvcr71d.dll!_free_dbg(void * pUserData=0x011b4f88, int nBlockUse=1) Line 1070 + 0xd C
mfc71d.dll!operator delete(void * p=0x011b4f88) Line 369 + 0xc C++
SCC-COM.exe!SCCCOM::CSccIop::Run(int argc=4, char * * argv=0x00d86108) Line 3131 + 0x17 C++
SCC-COM.exe!SCCCOM::CSccCom::Run(int argc=4, char * * argv=0x00d86108) Line 3808 + 0x10 C++
SCC-COM.exe!main(int argc=4, char * * argv=0x00d86108) Line 3881 + 0x13 C++
SCC-COM.exe!mainCRTStartup() Line 398 + 0x11 C
kernel32.dll!7c816fd7()