Reputation: 71
Using Visual Studio Express 2010 I made a Windows project with the options Windows Application and Empty Project. I then tried the following code snippet from the MSDN Windows tutorials:
#include <windows.h>
#include <shobjidl.h>
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOpenDialog *pFileOpen;
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr))
{
// Show the Open dialog box.
hr = pFileOpen->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
// Display the file name to the user.
if (SUCCEEDED(hr))
{
MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
CoTaskMemFree(pszFilePath);
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
return 0;
}
I got the following errors:
1>------ Rebuild All started: Project: Test05, Configuration: Debug Win32 ------
1> Test05.cpp
1>Test05.obj : error LNK2019: unresolved external symbol @_RTC_CheckStackVars@8
referenced in function _wWinMain@16
1>Test05.obj : error LNK2019: unresolved external symbol __RTC_CheckEsp referenced in
function _wWinMain@16
1>Test05.obj : error LNK2001: unresolved external symbol __RTC_Shutdown
1>Test05.obj : error LNK2001: unresolved external symbol __RTC_InitBase
1>LINK : error LNK2001: unresolved external symbol _wWinMainCRTStartup
What's going on here? Best I can tell something to do with wWinMain
, but it is copied directly from the site.
Compilers seem to be far more trouble for me than learning programming. I decided on Visual C++ after trying a few others (codeblocks mostly), but since Visual C++ seems to have the most support (or at least the majority of users) I figured it was better than never getting anywhere since they all are so unintuitive to a beginner.
Upvotes: 7
Views: 20735
Reputation: 1240
The _RTC_xxx symbols are added when the 'Basic Runtime Checks' are used; to disable them, you can go on the project properties, and set the Configuration Properties>C/C++>All Options>Basic Runtime Checks option to 'Default'. Though, as mentioned in the other answers, it looks like you have a mismatch in the C-Runtime libraries.
Upvotes: 9
Reputation: 40818
I would download the complete code sample from the link here rather than copying and pasting that code snippet you linked to. There may be important compiler/linker settings in the project files that are not being shown there. The sample is a VS 2008 solution, but I was able to upgrade it to a 2010 solution and build it. However, it gave me 'fatal linker error: could not find 'kernel32.lib'' when I tried to build it in VS 2008.
Upvotes: 0
Reputation: 7462
It looks like you're linking againt a different verison of the runtime libraries than what you're compiling against.
Please make sure you have only one version of Visual Studio installed and in path.
If you have more than one version, try to temporarily rename root directories of other Visual Studio installations to see if this will cause any effect.
Upvotes: 0