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)how to change?
# 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
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.comCodePudding user response:
Public: static class CThostFtdcTraderApi * __clrcall CThostFtdcTraderApi: : CreateFtdcTraderApi (CodePudding user response: