Hi,
I'm using visual c++.net 2003 and I'm having a problem getting
DllImportAttribute to import a function from a .dll...

The error message that I'm receiving:

LIBCMTD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol
_WinMain@16 referenced in function _WinMainCRTStartup
C:\DATA\Visual Studio Projects\eDNA Test Code\Debug\eDNA Test Code.exe :
fatal error LNK1120: 1 unresolved externals

Here is my code:

#include "stdafx.h"
#include "time.h"
#include <string>

#using <mscorlib.dll>

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::IO;
using namespace std;
using namespace System::Collections;

[DllImportAttribute("ezdnaapi.dll", EntryPoint= "DNAGetRTValueAsString",
CharSet=CharSet::Auto)]
extern int DNAGetRTValueAsString(char *szPoint, char *szValue, unsigned
short nValue);


The dll is in the systems32 folder.
Can anyone give me some advice with this?
thanks!
Sande

Re: DllImportAttribute problem with VC++.Net by William

William
Tue Apr 11 19:24:20 CDT 2006

"evilpixie" <evilpixie@discussions.microsoft.com> wrote in message
news:4535B31C-54CB-4FE2-BE4E-7AF2908065EB@microsoft.com...
> I'm using visual c++.net 2003 and I'm having a problem getting
> DllImportAttribute to import a function from a .dll...
>
> The error message that I'm receiving:
>
> LIBCMTD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol
> _WinMain@16 referenced in function _WinMainCRTStartup
> C:\DATA\Visual Studio Projects\eDNA Test Code\Debug\eDNA Test Code.exe :
> fatal error LNK1120: 1 unresolved externals
>
> Here is my code:
>
> #include "stdafx.h"
> #include "time.h"
> #include <string>
>
> #using <mscorlib.dll>
>
> using namespace System;
> using namespace System::Runtime::InteropServices;
> using namespace System::IO;
> using namespace std;
> using namespace System::Collections;
>
> [DllImportAttribute("ezdnaapi.dll", EntryPoint= "DNAGetRTValueAsString",
> CharSet=CharSet::Auto)]
> extern int DNAGetRTValueAsString(char *szPoint, char *szValue, unsigned
> short nValue);
>
>
> The dll is in the systems32 folder.
> Can anyone give me some advice with this?

The error message is telling you that it can't find a proper entry point for
your application. What kind of application do you want to build? Did you
create the project from scratch or use the wizard?

Regards,
Will



Re: DllImportAttribute problem with VC++.Net by evilpixie

evilpixie
Wed Apr 12 10:45:02 CDT 2006

I used the wizard. (Go to New->Project->select Console Application from
choices listed and then poof! Automagically I have a set of files.)

This code is eventually going to be in a Windows Service. I am
writing/testing it outside of the Service shell because I was told that it's
easier to debug that way. (I am new to VC++.Net) This advice came with the
advice to select the Console Application setup.

In the documentation for the .dll, it is listed as int WINAPI
DNAGetRTValueAsString(char *szPoint, char *szValue, unsigned short nValue)

If I list it as such in my code (with the windows.h header file) I get the
same error.

Thanks for your help, I really appreciate it!
Sande

"William DePalo [MVP VC++]" wrote:

> "evilpixie" <evilpixie@discussions.microsoft.com> wrote in message
> news:4535B31C-54CB-4FE2-BE4E-7AF2908065EB@microsoft.com...
> > I'm using visual c++.net 2003 and I'm having a problem getting
> > DllImportAttribute to import a function from a .dll...
> >
> > The error message that I'm receiving:
> >
> > LIBCMTD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol
> > _WinMain@16 referenced in function _WinMainCRTStartup
> > C:\DATA\Visual Studio Projects\eDNA Test Code\Debug\eDNA Test Code.exe :
> > fatal error LNK1120: 1 unresolved externals
> >
> > Here is my code:
> >
> > #include "stdafx.h"
> > #include "time.h"
> > #include <string>
> >
> > #using <mscorlib.dll>
> >
> > using namespace System;
> > using namespace System::Runtime::InteropServices;
> > using namespace System::IO;
> > using namespace std;
> > using namespace System::Collections;
> >
> > [DllImportAttribute("ezdnaapi.dll", EntryPoint= "DNAGetRTValueAsString",
> > CharSet=CharSet::Auto)]
> > extern int DNAGetRTValueAsString(char *szPoint, char *szValue, unsigned
> > short nValue);
> >
> >
> > The dll is in the systems32 folder.
> > Can anyone give me some advice with this?
>
> The error message is telling you that it can't find a proper entry point for
> your application. What kind of application do you want to build? Did you
> create the project from scratch or use the wizard?
>
> Regards,
> Will
>
>
>

Re: DllImportAttribute problem with VC++.Net by William

William
Wed Apr 12 10:52:26 CDT 2006

"evilpixie" <evilpixie@discussions.microsoft.com> wrote in message
news:9C317201-F56B-4DBD-98C9-3C6758190B42@microsoft.com...
>I used the wizard. (Go to New->Project->select Console Application from
> choices listed and then poof! Automagically I have a set of files.)
>
> This code is eventually going to be in a Windows Service. I am
> writing/testing it outside of the Service shell because I was told that
> it's
> easier to debug that way. (I am new to VC++.Net) This advice came with
> the
> advice to select the Console Application setup.
>
> In the documentation for the .dll, it is listed as int WINAPI
> DNAGetRTValueAsString(char *szPoint, char *szValue, unsigned short nValue)
>
> If I list it as such in my code (with the windows.h header file) I get the
> same error.

OK. Does your application begin executing user code at main() as windowed
applications start at WinMain()?

> Thanks for your help, I really appreciate it!

You are welcome.

Regards,
Will



Re: DllImportAttribute problem with VC++.Net by evilpixie

evilpixie
Wed Apr 12 11:18:02 CDT 2006

It begins executing at int _tmain().

"William DePalo [MVP VC++]" wrote:

> "evilpixie" <evilpixie@discussions.microsoft.com> wrote in message
> news:9C317201-F56B-4DBD-98C9-3C6758190B42@microsoft.com...
> >I used the wizard. (Go to New->Project->select Console Application from
> > choices listed and then poof! Automagically I have a set of files.)
> >
> > This code is eventually going to be in a Windows Service. I am
> > writing/testing it outside of the Service shell because I was told that
> > it's
> > easier to debug that way. (I am new to VC++.Net) This advice came with
> > the
> > advice to select the Console Application setup.
> >
> > In the documentation for the .dll, it is listed as int WINAPI
> > DNAGetRTValueAsString(char *szPoint, char *szValue, unsigned short nValue)
> >
> > If I list it as such in my code (with the windows.h header file) I get the
> > same error.
>
> OK. Does your application begin executing user code at main() as windowed
> applications start at WinMain()?
>
> > Thanks for your help, I really appreciate it!
>
> You are welcome.
>
> Regards,
> Will
>
>
>

Re: DllImportAttribute problem with VC++.Net by William

William
Wed Apr 12 12:03:00 CDT 2006

"evilpixie" <evilpixie@discussions.microsoft.com> wrote in message
news:D2C452FC-AC6B-4BD2-9D3C-4ECA24D81D85@microsoft.com...
> It begins executing at int _tmain().

Then that is your problem. The linker is telling you that it can't find
WinMain(). It is doing that presumably because you asked the wizard to
create something other than a "console application".

You have two choices:

1) You can go back and recreate a new "console application" project.

2) You can replace _tmain() with this

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
);

And if you need the tradional argc and argv variables they are available as

extern int _argc;
extern char **_argv;

The trouble with this approach is that you can not use the C standard I/O
(printf) or C++ output streams (std::cout) without extra work. Rather, you
are expected to use windows as display elements.

Regards,
Will







Regards,
Will