How to import C static libraries in windows forms application vC ++

I created one static library "C" using VS.

I use the same library file as another VS C console application, it works fine, but when I work with windows, the application does not work.

On this forum, so many requests were asked, but did not receive help.

Are there any naming conventions for invoking static library functions from Windows Managed C ++ forms?

Getting Errors Like This

error LNK2028: unresolved token (0A000032) "enum STATUS __clrcall xyz (unsigned char)" (? xyz @@ $$ FYM? AW4STATUS @@ E @Z), which is referenced in the __catch $ function? button3_Click @ Form1 @Myapp @@ $$ FA $ AAMXP $ AAVObject @System @@ P $ AAVEventArgs @ 4 @@ Z $ 0

But I have to use the same static library for the console application and Windows.

+3
source share
1 answer

The linker error message gives a strong hint of what is going wrong. Pay attention to the calling convention __clrcallfor the undefined character, it tells you that the compiler considers these to be "CLR" functions. Managed code, of course, is not, they are __cdecl. There are more names too crippled. Note the "@@ $$ FYM? AW4STATUS @@ E @Z" curses in the title. Which tells you that the compiler thinks they were written in C ++ instead of C.

You need to explicitly tell the compiler about this, the .h file is not compatible enough. What do you do in the C ++ / CLI source code file:

#pragma managed(push, off)
extern "C" {
#include "yadayada.h"
}
#pragma managed(pop)

#pragmas , , . extern "C" {} #include , .h C.

+4

All Articles