[SOLVED]LoadLibrary call crashes with Visual Studio but not with Dev C++

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Hi.

I am having a very strange problem, which I have no clue about its cause.

I am using the following code sample to load Play's dll:

////
#include <windows.h>
#include <stdio.h>

int main()
{
printf("\nLoading...");
Sleep( 5000 );

if( !LoadLibrary( "E:/temp/EastWest/play_VST_x64.dll" ) )
MessageBox( NULL, "LoadLibrary error", "warning", MB_OK );

//exits with code 16 before getting here with VS2008

printf("\nOK");
Sleep( 5000 );

return 0;
}
////

The strange thing is, if I compile and run this with Dev C++, it runs fine, but if I compile it with Visual Studio 2008 ( a console empty project with the default settings ), it crashes if I run it from the "Release" folder, and exits with code 16 if I run it from the IDE.

Does anybody know what could it be? :shrug:

Thanks.
Last edited by umd on Tue Oct 13, 2009 1:15 pm, edited 1 time in total.
Free MIDI plugins and other stuff:
https://jstuff.wordpress.com
"MIDI 2.0 is an extension of MIDI 1.0. It does not replace MIDI 1.0(...)"

Post

use backslashes (\) instead of forward ones (/)

plus its always better to set a searching path using SetDllDirectory func...
Demalkean

Post

For C or C++ string literals make that double backslashes (\\) instead of single ones (\). Call GetLastError after LoadLibrary to get a meaningful error code.

//Daniel

Post

Thanks for the tips, guys.

Unfortunately that didn't make any difference.

I can't call GetLastError() after, because it crashes/exits during the LoadLibrary call.
Free MIDI plugins and other stuff:
https://jstuff.wordpress.com
"MIDI 2.0 is an extension of MIDI 1.0. It does not replace MIDI 1.0(...)"

Post

are u using 64-bit os?
are you building 64-bit app? cuz i see you accessing 64-bit dll...

btw, is error code 16 in hex repres-tion?
Demalkean

Post

Arkadey wrote:are u using 64-bit os?
are you building 64-bit app? cuz i see you accessing 64-bit dll...

btw, is error code 16 in hex repres-tion?
Yes, I am using Windows 7 x64.

I am building a 32bit app ( Oops, that dll was renamed to end in "_x64" to test a bugfix not related to this, I forgot to change it back, it's a 32bit dll. ).

The error code is in decimal.

I suspect it may be something in the project's settings.
Free MIDI plugins and other stuff:
https://jstuff.wordpress.com
"MIDI 2.0 is an extension of MIDI 1.0. It does not replace MIDI 1.0(...)"

Post

ok. i don't know

there could be some Unicode (TEXT(x)) issues or UAC issues (insufficient priv. issues)..

prolly the problem is in the dll itself?

did try to

try {} catch (...)

or

__try {} __except( EXCEPTION_EXECUTE_HANDLER ) {}

that LoadLib call ???

win exit codes:

Code Description
0 The operation completed successfully.
1 Incorrect function.
2 The system cannot find the file specified.
3 The system cannot find the path specified.
4 The system cannot open the file.
5 Access is denied.
6 The handle is invalid.
7 The storage control blocks were destroyed.
8 Not enough storage is available to process this command.
9 The storage control block address is invalid.
10 The environment is incorrect.
11 An attempt was made to load a program with an incorrect format.
12 The access code is invalid.
13 The data is invalid.
14 Not enough storage is available to complete this operation.
15 The system cannot find the drive specified.
16 The directory cannot be removed.
17 The system cannot move the file to a different disk drive.
18 There are no more files.
19 The media is write protected.
20 The system cannot find the device specified.
21 The device is not ready.
22 The device does not recognize the command.
23 Data error (cyclic redundancy check).
Demalkean

Post

Unfortunately no clue yet.

I'll dig into the project's settings to see if I can find anything.

Thanks for trying.
Free MIDI plugins and other stuff:
https://jstuff.wordpress.com
"MIDI 2.0 is an extension of MIDI 1.0. It does not replace MIDI 1.0(...)"

Post

When you say it 'crashes' what is the error message you receive ? What is the stack trace ? Likely the problem is with the DLL you are loading. Build a debug version of the DLL and step through DllMain.

//Daniel

Post

A-ha!

After some trial and error with every option that could somehow be related with permissions, I found the problem. :bang:

For future reference, here's the cause:

Image

Setting DEP to "not compatible(...)" solves it (it's set to "compatible" by default), otherwise the compiled code won't load some copy-protected VST's in Win 7/Vista ( Play, Altiverb, Melodyne, etc ):

Hope this avoids headaches for someone else in the future.

Thanks once again for your time. ;-)
Free MIDI plugins and other stuff:
https://jstuff.wordpress.com
"MIDI 2.0 is an extension of MIDI 1.0. It does not replace MIDI 1.0(...)"

Post

This should be a sticky post for anyone writing hosts.

Post

These days there's a lot of things in your computer trying to decide for you what you should run in it or not. :x I want to decide myself.
Free MIDI plugins and other stuff:
https://jstuff.wordpress.com
"MIDI 2.0 is an extension of MIDI 1.0. It does not replace MIDI 1.0(...)"

Post Reply

Return to “DSP and Plugin Development”