HighTechTalks DotNet Forums  

Linker-Error: LNK2028 when calling a native function from managed wrapper

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Linker-Error: LNK2028 when calling a native function from managed wrapper in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ralf
 
Posts: n/a

Default Linker-Error: LNK2028 when calling a native function from managed wrapper - 09-05-2006 , 01:35 AM






Hi,

I want to call a (static) native function "DeleteInstance".
These methods looks like in the header-file:
static void DeleteInstance();

and in the cpp-file:
void CMessenger:eleteInstance()
{
if (mpMessenger)
{
delete mpMessenger;
mpMessenger = NULL;
}
}

But I only get this linker error:
===================================
Error 19 error LNK2028: unresolved token (0A000293) "public: static
class MessLib::CMessenger & __cdecl
MessLib::CMessenger:eleteInstance(void)"
(?DeleteInstance@CMessenger@MessLib@@$$FSAAAV12@XZ ) referenced in
function "public: static class DotNetMessLib::Messenger ^ __clrcall
DotNetMessLib::Messenger:eleteInstance(void)"
(?DeleteInstance@Messenger@DotNetMessLib@@$$FSMP$A AV123@XZ) Messenger.obj
===================================
and the (I think resulting) linker error:
Error 20 error LNK2019: unresolved external symbol "public: static void
__cdecl MessLib::CMessenger:eleteInstance(void)"
(?DeleteInstance@CMessenger@MessLib@@$$FSAXXZ) referenced in function
"public: static void __clrcall
DotNetMessLib::Messenger:eleteInstance(void)"
(?DeleteInstance@Messenger@DotNetMessLib@@$$FSMXXZ ) Messenger.obj
===================================

The msdn-help is not really helpful:
"When attempting to import a native function into a pure image,
remember that the implicit calling conventions differ between native
and pure compilations."
But I don't use a pure image. I just compile my wrapper with /clr, not
/clrure.

I've seen that some people get the same problems, but they worked with
preprocessor-macros. The only macros in my code are:
#ifndef _MESSENGER_H_
#define _MESSENGER_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

.....
#endif // _MESSENGER_H_

My wrapper code looks like:
void DotNetMessLib::Messenger:eleteInstance()
{
MessLib::CMessenger:eleteInstance();
mpMessenger = nullptr;
}
(in the header-file this method is defined static: static void
DeleteInstance()

To access the classes from the native library I included the native
"messenger.lib" file in my wrapper project settings.

What did I do wrong? How can I avoid these linker errors?

Thanks a lot for your help!

Best regards
Ralf


Reply With Quote
  #2  
Old   
David Wright
 
Posts: n/a

Default Re: Linker-Error: LNK2028 when calling a native function from managed wrapper - 08-08-2007 , 01:32 AM






Try the following statement somewhere in your exe...

#using "messenger.dll"

dave
:-*)


"Ralf" <ralf (AT) abramowitsch (DOT) de> wrote

Quote:
Hi,

I want to call a (static) native function "DeleteInstance".
These methods looks like in the header-file:
static void DeleteInstance();

and in the cpp-file:
void CMessenger:eleteInstance()
{
if (mpMessenger)
{
delete mpMessenger;
mpMessenger = NULL;
}
}

But I only get this linker error:
===================================
Error 19 error LNK2028: unresolved token (0A000293) "public: static
class MessLib::CMessenger & __cdecl
MessLib::CMessenger:eleteInstance(void)"
(?DeleteInstance@CMessenger@MessLib@@$$FSAAAV12@XZ ) referenced in
function "public: static class DotNetMessLib::Messenger ^ __clrcall
DotNetMessLib::Messenger:eleteInstance(void)"
(?DeleteInstance@Messenger@DotNetMessLib@@$$FSMP$A AV123@XZ) Messenger.obj
===================================
and the (I think resulting) linker error:
Error 20 error LNK2019: unresolved external symbol "public: static void
__cdecl MessLib::CMessenger:eleteInstance(void)"
(?DeleteInstance@CMessenger@MessLib@@$$FSAXXZ) referenced in function
"public: static void __clrcall
DotNetMessLib::Messenger:eleteInstance(void)"
(?DeleteInstance@Messenger@DotNetMessLib@@$$FSMXXZ ) Messenger.obj
===================================

The msdn-help is not really helpful:
"When attempting to import a native function into a pure image,
remember that the implicit calling conventions differ between native
and pure compilations."
But I don't use a pure image. I just compile my wrapper with /clr, not
/clrure.

I've seen that some people get the same problems, but they worked with
preprocessor-macros. The only macros in my code are:
#ifndef _MESSENGER_H_
#define _MESSENGER_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

....
#endif // _MESSENGER_H_

My wrapper code looks like:
void DotNetMessLib::Messenger:eleteInstance()
{
MessLib::CMessenger:eleteInstance();
mpMessenger = nullptr;
}
(in the header-file this method is defined static: static void
DeleteInstance()

To access the classes from the native library I included the native
"messenger.lib" file in my wrapper project settings.

What did I do wrong? How can I avoid these linker errors?

Thanks a lot for your help!

Best regards
Ralf




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.