views:

1342

answers:

4

Hello,

>My previous thread<

I created this one,because I installed WinXP on VMBox and I cannot get it working again.

This time I created an OnLoad Event on my form

        if (LoadLibrary("blowfish.dll") == 0)
        {
            Misc.LogToFile("Could not load dll", true);
            Application.Exit();
        }

Runs fine on my PC,but on VMBox LoadLibrary returns 0.

Some users mentioned that the problem would be in mixing older NET Framework(2.0) with dlls made on newest MS Visual studio(2008 SP1) so I took action and now the program properties it's set to work with NET 3.5

On the VMBox I have NET 2.0,but this is not the problem - the program itself runs fine.I also have C++ Redistributable(2005,2005 SP1 and 2008).

What could be the problem?

A: 

It could be that the dll's location is on the path in one environment and not in the other. It could also be permissions in one environment are not the same as the other.

JP Alioto
Check my previous thread,the hyper link is the first line!I don't need LoadLibrary,I use external functions.I just set that code to make sure the problem is in the dll.
John
A: 

Try running dependency walker on the DLL - see if any modules are missing.

Aardvark
No,everything is fine.
John
If a dll is missing which gets loaded dynamically by any of the libraries in the dependency tree you will not be able to track that with dependency walker. So a missing library might still be the reason.
0xA3
You're right, divo. However, Dependency Walker (newer versions) has a profiling mode where it actually can help in tracking down these dynamically loaded modules.
Aardvark
A: 

Call GetLastError after LoadLibrary, check the error code value here: http://msdn.microsoft.com/en-us/library/ms681381.aspx and see if that helps.

Michał Piaskowski
+1  A: 

To further trouble should you could call

Marshal.GetLastWin32Error();

which should give you an error code.

Is it possible that you deployed a debug version of your native dll which also requires a debug version of MSVCR90**D**.DLL? You should have distributed the release version because the debug version requires a different set of dlls to be present on the target system.

It obviously works on your development machine because all debug versions of the required libraries come with Visual Studio.

This is how you would get the message belonging to an error code:

[DllImport("kernel32.dll")]
private unsafe static extern int FormatMessage(int dwFlags, 
    int lpSource, int dwMessageId, int dwLanguageId, 
    ref String lpBuffer, int nSize, int Arguments);

public static string GetErrorMessage(int errorCode)
{
    int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
    int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
    int FORMAT_MESSAGE_FROM_SYSTEM  = 0x00001000;

    int messageSize = 255;
    string lpMsgBuf = "";
    int dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER 
       | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;

    int retVal = FormatMessage(dwFlags, 0, errorCode, 0, 
                               ref lpMsgBuf, messageSize, 0);
    if (0 == retVal) 
    {
        return null;
    }
    else
    {
        return lpMsgBuf;
    }
}
0xA3
As String I get "This application has failed to start because its application configuration is incorrect".The error code is 14001.Please tell me how to fix the application configuration of the dll?In the DLL project folder I have two filders - Blowfish and Debug.The dll is from the Debug folder.
John
Can you try the release build?
0xA3
I didn't know the difference between debug and release build and I didn't know how to make it compile the release build,but now,thanks to you - I do! Millions of thanks buddy!
John