Implementing extern WINAPI call in MFC C++ App

2019-08-11 17:45发布

问题:

I am working with Windows Form App C++. I have to use some header file that has

HRESULT extern WINAPI StartUp ( DWORD dwVRequired, LPVERSION lpVersion);

I have to execute this method within Form1.h

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    APPVERSION version;
    HRESULT result = APPStartUp(APP_VERSIONS, &version);
}

But I am getting the compile error like this

Error 1 error LNK2028: unresolved token (0A000025) "extern "C" long __stdcall APPStartUp(unsigned long,struct _version *)" (?WFSStartUp@@$$J18YGJKPAU_wfsversion@@@Z) referenced in function "private: void __clrcall MyAppPresenter::Form1::Form1_Load(class System::Object ^,class System::EventArgs ^)" (?Form1_Load@Form1@MyAppPresenter@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) C:\Projects\MyAppPresenter\MyAppPresenter\MyAppPresenter.obj MyAppPresenter

I assume it has something to do with MSVS2010 C++ Console Code Ported to MSVS2010 C++ GUI is Failing. Why?

But how it can be done? Any clue how it could be fixed?

回答1:

I checked the console C++ project and found that *.vsxproj has

<ItemGroup>
    <Library Include="C:\Program Files\Common Files\GCFApp\lib\msmanager.lib" />
</ItemGroup>

So I just added this code to the Windows Form C++ project file manually and now it works.

Anyway I have no clue how to add it using GUI of VS 2010.