Converting a .NET 1.1 Mixed DLL to .NET 2.0 (newbie)

V

vs

I have the source code of a DLL compiled on VS2003 with .NET 1.1.
I am trying to convert it to .NET 2.0 with VS2005.

Apparently, many issues with mixed mode dll's have been fixed with
VS2005 but I still do not understand what is happening.

In the source code, there is the following file which I beleive is the
source of my problem.

===============================================================
MixedDll.cpp
==================================
// This code verifies that DllMain is not automatically called
// by the Loader when linked with /noentry. It also checks some
// functions that the CRT initializes.

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include "_vcclrit.h"

#using <mscorlib.dll>
using namespace System;

namespace ODE
{
public __gc class ManagedWrapper
{
public:
static void Initialize()
{
//__crt_dll_initialize();
}
static void Terminate()
{
//__crt_dll_terminate();
}
};
}

//BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID)
//{
// return TRUE;
//}
======================================================

- The added comments were put there by me so it would compile OK

- I also removed "/no entry" from the command line arguments.

When I add the reference to this new DLL I can browse it's objects in
the visual studio "object browser" without a problem so I know
something is working.
However, when I try to initialize an object in my code from this DLL, I
get a FileNotFound exception. (this used to work with the old DLL so I
know I messed something up)

Any suggestions?

V.
 
M

Marcus Heege

vs said:
I have the source code of a DLL compiled on VS2003 with .NET 1.1.
I am trying to convert it to .NET 2.0 with VS2005.

Apparently, many issues with mixed mode dll's have been fixed with
VS2005 but I still do not understand what is happening.

In the source code, there is the following file which I beleive is the
source of my problem.

===============================================================
MixedDll.cpp
==================================
// This code verifies that DllMain is not automatically called
// by the Loader when linked with /noentry. It also checks some
// functions that the CRT initializes.

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include "_vcclrit.h"

#using <mscorlib.dll>
using namespace System;

namespace ODE
{
public __gc class ManagedWrapper
{
public:
static void Initialize()
{
//__crt_dll_initialize();
}
static void Terminate()
{
//__crt_dll_terminate();
}
};
}

//BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID)
//{
// return TRUE;
//}
======================================================

- The added comments were put there by me so it would compile OK

- I also removed "/no entry" from the command line arguments.

When I add the reference to this new DLL I can browse it's objects in
the visual studio "object browser" without a problem so I know
something is working.
However, when I try to initialize an object in my code from this DLL, I
get a FileNotFound exception. (this used to work with the old DLL so I
know I messed something up)

Any suggestions?

V.

The code above was necessary to avoid the loader lock problem of mixed code
DLLs. I assume you have added this code because of this [1] article.

In .NET 2.0, this is no longer necessary. [2] Tells you how to get rid of
the unnecessary code and compiler flags.

If you consider adding DllInit code in the future, you should be aware that
you should still *not* allowed to compile DllInit to managed code to call
any manated code in DllInit.

Marcus Heege
www.heege.net

[1]
http://msdn.microsoft.com/library/d...tsfrompureintermediatelanguagetomixedmode.asp
[2] http://msdn2.microsoft.com/library/ms173267(en-US,VS.80).aspx
 
H

Holger Grund

vs said:
- The added comments were put there by me so it would compile OK

- I also removed "/no entry" from the command line arguments.

When I add the reference to this new DLL I can browse it's objects in
the visual studio "object browser" without a problem so I know
something is working.
However, when I try to initialize an object in my code from this DLL, I
get a FileNotFound exception. (this used to work with the old DLL so I
know I messed something up)
It's likely a missing manifest in your DLL. In VC++2005 /clr implies
/MD (the shared CRT). Your DLL will not load correctly unless you
embed the manifest into your resources.

You can open your DLL in the resource editor and check if there
is a resource of type RT_MANIFEST. If it is not there you need
to add it.

If you're building from within IDE, make sure that
- add a #include <crtdefs.h> in at least one of the compilands
- you have the manifest tool checked in the "Tool Build Order" dialog of
the project.

The first step adds a linker pragma for the /manifestdependency switch.
When the code is linked the linker generates a separate manifest file.
Finally mt.exe will embed that as a resource into your DLL.

-hg
 
K

kjobson

Thank you very much,

I also had to create a new key file to get the assembly signed.

bye
 
K

kjobson

Thank you very much,

I also had to create a new key file to get the assembly signed.

bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top