Creating a .NET wrapper around C library

P

Paul Brun

Hi guys,

I would like to find out if :
1) Is the above possible?

I have tried to wrap a C library that our company produces in a .Net class
library and am receiving the
following error:

LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol
_main referenced in function _mainCRTStartup

Now....what seems to be weird is when I comment out the line that I am
referencing from the C library,
I have no problems linking....however, the minute I include the line....I
get the above error. Am I doing
something wrong? I thought that since the previous library was created as a
library, then just linking it
in and making sure I cover the Managed C++ part of the puzzle correctly, I
would have no problems.

Please comment.

Thanks
Paul
 
W

William DePalo [MVP VC++]

Paul Brun said:
I would like to find out if :
1) Is the above possible?

Yes, it is.
I have tried to wrap a C library that our company produces in a .Net class
library and am receiving the
following error:

LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol
_main referenced in function _mainCRTStartup

Can it be that this issue is biting you:


http://support.microsoft.com/?id=814472

Regards,
Will
 
G

Guest

Hi
If u r using a managed extension for .Net Application development the recompile ur c lib code on .Net with managed optio
or if u want to use unmanaged c extension lib code then use unmanaged option in ur .Net development environment.
 
P

Paul Brun

I have read this article in detail and have gone through their
recommendations, but it doesn't
help. The library that I am linking with statically does not contain an
entry point for "main", it
is a "lib", so this really doesn't make to much sense.

The article states:

-------------
Managed Extensions for C++ projects that are created as DLLs by default do
not link to native C/C++ libraries such as the C run-time (CRT) library,
ATL, or MFC and do not use any static variables. Additionally, the project
settings specify that the DLLs should be linked with the /NOENTRY option
enabled.
-------------

What does that mean? I won't be able to link with my C library at all. I do
have the /NOENTRY option in my project
settings.

Any other options?

Thanks
Paul
 
P

Paul Brun

However, if I compile without the managed option, then I won't be able to
have a VB application use the class, right?

Paul

Rakesh Khanduja said:
Hi,
If u r using a managed extension for .Net Application development the
recompile ur c lib code on .Net with managed option
or if u want to use unmanaged c extension lib code then use unmanaged
option in ur .Net development environment.
 
F

Frank Lopez

My suggestion:

1) try getting the unmanaged DLL compiled all by itself without any
errors as part of the .NET solution.
if you have problems making this work, take the unmanaged project file used by Microsoft and replace the source files within it with your files.

2) decide whether or not you are going to use a proxy layer DLL that
has the managed to unmanaged C++ class mappings, or are you going to
call the unmanaged code directly from your managed code

3) start with one small test case from your .NET application and get
it to work so that you know you are doing the basics right

For the managed project that you start, remember to select "debug
unmanaged" code if you want to be able to step into unmanaged code
from your managed code.

Good luck.

Frank
 
G

Guest

It might help to call the _CRT_INIT function in your Dllmain.
I think there are some examples on the web about how to do thi
It helps avoid some microsoft bug relating to managed dlls an
dll entry points
 

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