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?
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.
Related
I am trying to get to grips with using Windows API functions, but making them work properly is proving difficult.
In VS2015, my C++ code currently produces linker errors whenever I call MessageBox() or anything similar:
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace System;
int main()
{
Console::WriteLine(L"Hello World");
MessageBox(NULL, L"Stuff", L"Things", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
The errors I get are an unresolved token and an unresolved external symbol, with MessageBoxW appearing in the messages.
One of the error messages:
Error LNK2028 unresolved token (0A0004E9) "extern "C" int stdcall MessageBoxW(struct HWND *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW##$$J216YGHPAUHWND__##PB_W1I#Z) referenced in function "extern "C" int cdecl MessageBox(struct HWND *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox##$$J0YAHPAUHWND__##PB_W1I#Z)
You accidentally created a .net project, which implies you aren't going to be using the Windows API, at least not without some changes to your project. You need to create a Win32 project, not a .net project.
It is perfectly fine to utilize WinAPI interfaces in the C++/CLI project, if your intention is to use only managed interfaces it is simpler to create a fully managed project (C#).
What you're missing here is a library inputs for linker (User32.lib as mentioned before in the comments).
See Calling native Win32 code from .NET (C++/CLI and C#) for the similar issue.
I'm learning OpenGL using superbible 6th edition and while compiling this code:
#include <iostream>
#include "sb6.h"
class my_application : public sb6::application
{
public:
void render(double currentTime)
{
static const GLfloat red[] = { 1.0f,0.0f,0.0f,1.0f };
glClearBufferfv(GL_COLOR, 0, red);
}
};
DECLARE_MAIN(my_application);
I'm getting a linking errors saying cannot open sb6_d32.lib
I searched the entire sb6 directory there is no sb6_d32.lib file available for it to open so that i can link it? Am i missing something?
Edit: 2 Unresolved externals
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ) OpenGL_learning E:\C++\Learning\OpenGL\OpenGL_learning\OpenGL_learning\MSVCRTD.lib(exe_main.obj) 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol __imp____iob_func referenced in function __glfwPlatformOpenWindow OpenGL_learning E:\C++\Learning\OpenGL\OpenGL_learning\OpenGL_learning\GLFW_d32.lib(win32_window.obj) 1
You have to build it first. See HOWTOBUILD.txt file in your examples folder root:
Windows / Microsoft Visual Studio 2010:
Project files are included in the source archive for Visual Studio
2010. These will work with Professional (all tiers) and Express editions. Newer versions of Visual Studio should import them just
fine, but this is not extensively tested. Simply open the sb6.sln file
in Visual Studio and hit build (F7). Evertything will build and you'll
end up with binaries in the 'bin' directory.
Update: Unresolved externals.
LNK2019 unresolved external symbol _main referenced in
function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
Lets see DECLARE_MAIN macro implementation in the sb6.h:
#if defined _WIN32
#define DECLARE_MAIN(a) \
sb6::application *app = 0; \
int CALLBACK WinMain(HINSTANCE hInstance, \
HINSTANCE hPrevInstance, \
LPSTR lpCmdLine, \
int nCmdShow) \
{ \
a *app = new a; \
app->run(app); \
delete app; \
return 0; \
}
If you want to use this macro, your program should be compiled as windows application (/SYBSYSTEM:WINDOWS), you are creating console application which is not supported. Change subsystem in your project settings (Linker/System).
LNK2019 unresolved external symbol __imp____iob_func
referenced in function __glfwPlatformOpenWindow
See this for the ways to solve that problem. In short you have to recompile all used static libraries with your version of Visual Studio.
I created a CLR Class Library where I am wanting to do some WASAPI Core Audio processing. Finally got around to adding the COM stuff, and I've stripped it all down to simply this:
bool AudioLibrary::AudioClass::initializeAudioDevices()
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (FAILED(hr))
{
// Big problem
return hr;
}
}
This is extremely basic, and compiles just fine (my namespace is obviously AudioLibrary and the class is AudioClass). However, during link I get this:
Error 9 error LNK2028: unresolved token (0A000029) "extern "C" long __stdcall CoInitializeEx(void *,unsigned long)" (?CoInitializeEx##$$J18YGJPAXK#Z) referenced in function "private: bool __clrcall AudioLibrary::AudioClass::initializeAudioDevices(void)" (?initializeAudioDevices#AudioClass#AudioLibrary##$$FA$AAM_NXZ) C:\Users\Administrator\Documents\Visual Studio Projects\WindowsFormsApplication1\AudioLibrary\AudioLibrary.obj AudioLibrary
I've got Windows.h and objbase.h included, but I'm obviously missing some type of link reference. I've tried both 'inherit from parent' and no inherit in the link options for the project.
Been doing too much IOS/Android/OSX programming lately so I'm apparently pretty stale on Visual Studio stuff. What am I missing to include CoInitializeEx? I'm using Visual Studio 2013 Ultimate. Thanks!
I'm using a 3rd party COM-based library called Engine in a native WinRT component which should later act as a wrapper for the 3rd party lib.
An Engine.lib and a Engine.h file for the 3rd party lib is setup in my project.
I'm getting the LNK2019 for my following cpp file:
#include "pch.h"
#include "Engine.h"
void Component::Init()
{
ComPtr<IEngine> spEngine;
Settings settings;
CreateEngine(&settings, &spEngine);
}
The code compiles fine and the Engine.lib is setup in the project settings of VS2012. Also does DUMPBIN /EXPORTS for the Engine.lib show that CreateEngine is exposed. I can also use other types defined in the Engine.h, but as soon as CreateEngine is called, a linker error is raised:
Error 1 error LNK2019: unresolved external symbol CreateEngine#8 referenced in function "public: virtual void __cdecl
Engine.h defines CreateEngine like this:
STDAPI CreateEngine(
_In_ Settings * pSettings,
_Outptr_ IEngine **ppEngine );
Where the STDAPI is the usual macro:
#define STDAPI extern "C" HRESULT __stdcall
Any ideas?
Figured it out with the help of Inspired: I was using the lib built for ARM with an x86 build configuration. After changing that it was linking fine.
I am having a LNK2028 error when I try to build my C++/CLI dll. I am using a static lib called pano13 in my program, and I am using one method of it. Everything in my program is fine except the one method call I make to the library, where I get these exact two exceptions.
Error 21 error LNK2028: unresolved token (0A00013B) "int __cdecl panoCreatePanorama(struct fullPath * const,int,struct fullPath *,struct fullPath *)" (?panoCreatePanorama##$$FYAHQAUfullPath##HPAU1#1#Z) referenced in function "public: int __clrcall Surgeon::Stitcher::StitchImage(class System::Collections::Generic::List<class System::String ^> ^,class System::String ^)" (?StitchImage#Stitcher#Surgeon##$$FQ$AAMHP$AAV?$List#P$AAVString#System###Generic#Collections#System##P$AAVString#6##Z) C:\Users\ndean_000\Documents\Visual Studio 2012\Projects\C#\CameraTest\Surgeon\Surgeon.obj Surgeon
Error 22 error LNK2019: unresolved external symbol "int __cdecl panoCreatePanorama(struct fullPath * const,int,struct fullPath *,struct fullPath *)" (?panoCreatePanorama##$$FYAHQAUfullPath##HPAU1#1#Z) referenced in function "public: int __clrcall Surgeon::Stitcher::StitchImage(class System::Collections::Generic::List<class System::String ^> ^,class System::String ^)" (?StitchImage#Stitcher#Surgeon##$$FQ$AAMHP$AAV?$List#P$AAVString#System###Generic#Collections#System##P$AAVString#6##Z) C:\Users\ndean_000\Documents\Visual Studio 2012\Projects\C#\CameraTest\Surgeon\Surgeon.obj Surgeon
I am including the lib file in the project settings, and I even added the #pragma comment statement for including the library, however I am getting this error. I understand that it has to do with the mixing of native and managed C++, however I am not compiling the program with clr/pure, it is being compiled with the default clr compilation of /clr. Anyone have any ideas how to fix it?
By the way, I solved this a WHILE ago, but I should probably say what the issue was. The panotools library is a C library, not a C++ library. I didn't know that C libraries needed the extern C directive to be used in C++. So all I had to do to fix my problem was
extern "C"
{
#include <panorama.h>
}
Where panorama.h is the include file for the panotools C library. I've always wondered what extern C was for and now I finally understand its purpose.