Home > Software engineering >  C/CLR DLL call problem (an amazing problem, hope to solve)
C/CLR DLL call problem (an amazing problem, hope to solve)

Time:10-21

Now encountered a strange question,
Create a console application CLR console application, add the DLL and lib (engineering properties, lib directory and name is added to the DLL into dedug folder), compiled through,
no problemCreate a Windows Forms application, use the same method to add the DLL and lib, compile error, error is call DLL function is not successful,
DLL code below
//h file 

# if! Defined (_FTDCTRADERAPI_H)
# define _FTDCTRADERAPI_H

# if _MSC_VER & gt; 1000
# pragma once
# endif//_MSC_VER & gt; 1000

# include "ThostFtdcUserApiStruct. H"

# if defined (ISLIB) & amp; & Defined (WIN32)
# ifdef LIB_TRADER_API_EXPORT
# define TRADER_API_EXPORT __declspec (dllexport)
# the else
# define TRADER_API_EXPORT __declspec (dllimport)
# endif
# the else
# define TRADER_API_EXPORT
# endif

The class TRADER_API_EXPORT CThostFtdcTraderApi
{
Public:
The static CThostFtdcTraderApi * CreateFtdcTraderApi (const char * pszFlowPath="");
};


Console program, successfully run
 # include "stdafx. H" 


# include ". \ ThostTraderApi \ ThostFtdcTraderApi h "
Using the namespace System;

Int main (array ^ args)
{
CThostFtdcTraderApi * aa=CThostFtdcTraderApi: : CreateFtdcTraderApi ();
return 0;
}

Winform program
//2. CPP: the main project file.

# include "stdafx. H"
# include "Form1. H"
# include ". \ ThostTraderApi \ ThostFtdcTraderApi h "
Using the namespace My2;

[STAThreadAttribute]
Int main (array ^ args)
{
//Enabling Windows XP visual effects before any controls are created
Application: : EnableVisualStyles ();
Application: : SetCompatibleTextRenderingDefault (false);
CThostFtdcTraderApi * aa=CThostFtdcTraderApi: : CreateFtdcTraderApi ();

//Create the main window and run it
Application: : Run (gcnew _click ());
return 0;


}

The correct

The error LNK2028: unresolved token (0 a00000f) "public: static class CThostFtdcTraderApi * __clrcall CThostFtdcTraderApi: : CreateFtdcTraderApi (char const *)" (? CreateFtdcTraderApi @ CThostFtdcTraderApi @ @ $$FSMPAV1 @ PBD @ Z) referenced in the function "int __clrcall main (cli: : array ^)" (? The main @ @ $$$$AAVString 01 ap HYMHP @ System @ @ @ Z) I tried to remove the lib will appear the same mistake, namely in winform failed with

The two problems:
1, how can success under winform calls the lib and DLL
2, the individual did not say if the call fails h header file, namely the segment
 # if! Defined (_FTDCTRADERAPI_H) 
# define _FTDCTRADERAPI_H

# if _MSC_VER & gt; 1000
# pragma once
# endif//_MSC_VER & gt; 1000

# include "ThostFtdcUserApiStruct. H"

# if defined (ISLIB) & amp; & Defined (WIN32)
# ifdef LIB_TRADER_API_EXPORT
# define TRADER_API_EXPORT __declspec (dllexport)
# the else
# define TRADER_API_EXPORT __declspec (dllimport)
# endif
# the else
# define TRADER_API_EXPORT
# endif
how to change?
3, I try to establish the win32, MFC project, are able to compile successfully, this what is going on, o master,

CodePudding user response:

https://www.baidu.com/s? Wd=20 lnk2028 error % % % 20 unresolved % 3 a token % 20 (0 a00000f) % 20 site%3amicrosoft.com

CodePudding user response:

Public: static class CThostFtdcTraderApi * __clrcall CThostFtdcTraderApi: : CreateFtdcTraderApi (

CodePudding user response:

reference 1st floor zhao4zhong1 response:
https://www.baidu.com/s? Wd=20 lnk2028 error % % % 20 unresolved % 3 a token % 20 (0 a00000f) % 20 site%3amicrosoft.com

Hey, isn't this add DLL problem,

CodePudding user response:

refer to the second floor Dobzhansky response:
public: static class CThostFtdcTraderApi * __clrcall CThostFtdcTraderApi: : CreateFtdcTraderApi (

You mean to make me h header file instead? Didn't understand

CodePudding user response:

At present can't solve the problem, now can only use the console entry and then hide console to do,,
Don't know if master have know

CodePudding user response:

C the Run - Time Libraries http://msdn.microsoft.com/zh-cn/library/abx4dbyh (vs. 80). Aspx
?

CodePudding user response:

# pragma managed
# pragma fsound_unmanaged

Or set the CLR supporting for file,

  • Related