error C2061: syntax error : identifier 'IXMLDOMDocument' - c++

I'm building a GTK+ VS2010 project configuration on (VS2013) and I'm trying to add a browse folder functionality (I want to use Native Windows way). I'm using the following code:
#include <windows.h>
#include <ShlObj.h>
DWORD WINAPI BrowseFolder(void *ptr)
{
char path[MAX_PATH];
cchar * path_param = (cchar*)ptr;
BROWSEINFO bi = { 0 };
bi.lpszTitle = ("Select Folder");
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
bi.lpfn = BrowseCallbackProc;//callback function defined..
bi.lParam = (LPARAM)path_param;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
if (pidl != 0)
{
//get the name of the folder and put it in path
SHGetPathFromIDList(pidl, path);
//free memory used
IMalloc * imalloc = 0;
if (SUCCEEDED(SHGetMalloc(&imalloc)))
{
imalloc->Free(pidl);
imalloc->Release();
}
strcpy(g_sDefaultDir, path);
return 0;
}
}
but when compiling I'm getting this error message
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\shobjidl.h(17624): error C2061: syntax error : identifier 'IXMLDOMDocument'
This is my configuration:
I'm running VS2010 solution on VS2013
Use Standard Windows Libraries
Not Using ATL
and Use Multi-Byte character set
Any ideas?

I found 2 ways to answer solve my problem.
I had msxml and ISoftDistExt previously defined to solve ambiguity problem, so I had to #undef them like the following:
#undef __msxml_h__
#undef __ISoftDistExt_INTERFACE_DEFINED__
#include <MsXml.h>
#include <ShlObj.h>
Also, you can use the #import statement like the follownig
#undef __msxml_h__
#undef __ISoftDistExt_INTERFACE_DEFINED__
#import <msxml6.dll>
using namespace MSXML2;
#include <ShlObj.h>
Hope this will help someone later.

Related

C2065: 'D3DFORMAT': undeclared identifier

When I tried to compile simple GTA San Andreas ASI (dll) project using SDK, I saw error
C2065 'D3DFORMAT': undeclared identifier.
Line: RwBool _rwD3D9CheckValidCameraTextureFormat(D3DFORMAT format); // 0x4CBE20
Interesting thing is that, a few months ago, before reset to factory settings (Windows 10) all was ok.
I tried on Visual Studio 2015/2017/2019.
My code is so simple, because all is in SDK. (https://github.com/DK22Pac/plugin-sdk)
#include "plugin.h"
#include "common.h"
#include "CTimer.h"
#include "CStreaming.h"
using namespace plugin;
class PlayerWeapon {
public:
PlayerWeapon() {
static int keyPressTime = 0;
Events::gameProcessEvent += [] {
CPed *playa = FindPlayerPed();
if (playa && KeyPressed(VK_TAB) && CTimer::m_snTimeInMilliseconds - keyPressTime > 500) {
keyPressTime = CTimer::m_snTimeInMilliseconds;
CStreaming::RequestModel(MODEL_M4, 2);
CStreaming::LoadAllRequestedModels(false);
playa->GiveWeapon(WEAPON_M4, 10, true);
playa->SetCurrentWeapon(WEAPON_M4);
CStreaming::SetModelIsDeletable(MODEL_M4);
}
};
}
} playerWeapon;

Cannot open include file: 'cxxabi.h': No such file or directory

I am making a game that can be played on mac and windows with cocos2d-x.
I first wrote the code in mac's Xcode, and it worked on mac.
When I took the project to windows and tried to build it in Visual Studio 2017, an error occurred.
Error C1083 Cannot open include file: 'cxxabi.h': No such file or directory Narazumono c:\users\masanori\desktop\narazumono3.17\classes_win\nrzcoding.cpp 10
I use cxxabi.h to get the class name of the object.
#include "NRZCoding.h"
#include <cxxabi.h>
#include <cstdio>
#include <algorithm>
#include "NRZUtils.h"
using namespace std;
USING_NS_CC;
namespace NRZCoding {
...
const string& EncodableObject::getClassName()
{
if (_className.size() > 0) {
return _className;
}
const type_info& id = typeid(*this);
int stat;
char *name = abi::__cxa_demangle(id.name(),0,0,&stat);
CCASSERT(name != NULL && stat == 0, "failed to demangle");
_className = string(name);
free(name);
return _className;
}
...
What do I need to do?
I am using cocos2d-x 3.17.1 and Visual Studio 2017.
Thank you.

How to find the "Saved Games" folder programmatically in C/C++?

I am writing a game. I am planning to store saves in the "saved games" directory.
How to find the location of the Saved Games folder programmatically?
It needs to work on non-English Windows. Hacks like %USERPROFILE%\Saved Games are not an option.
The Saved Games directory can be located with the SHGetKnownFolderPath() function, available since Windows Vista and Windows Server 2008.
Note that the FOLDERID_SavedGames argument is a C++ reference. Replace with &FOLDERID_SavedGames to call from C code.
Tested successfully on the first online MSVC compiler I could find:
https://rextester.com/l/cpp_online_compiler_visual
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <stdio.h>
#include <shlobj.h>
#include <objbase.h>
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "ole32.lib")
int main(void)
{
PWSTR path = NULL;
HRESULT r;
r = SHGetKnownFolderPath(FOLDERID_SavedGames, KF_FLAG_CREATE, NULL, &path);
if (path != NULL)
{
printf("%ls", path);
CoTaskMemFree(path);
}
return 0;
}

C file cannot be compiled in c++ Visual Studio

For some reason I can no longer compile a c file in my c++ clr console application. It worked before without the clr support, I also switched my project to compile as /TP still not working. Any help would be greatly appreciated.
Error
Severity Code Description Project File Line Suppression State
Error C2664 'int strcmp(const char *,const char *)': cannot convert argument 1 from 'WCHAR [260]' to 'const char *'
snowkill.c
#include "snowkill.h"
void killProcessByName(WCHAR *filename)
{
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof(pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);
while (hRes)
{
if (strcmp(pEntry.szExeFile, filename) == 0)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,
(DWORD)pEntry.th32ProcessID);
if (hProcess != NULL && pEntry.th32ProcessID != GetCurrentProcessId())
{
TerminateProcess(hProcess, 9);
CloseHandle(hProcess);
}
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
}
snowkill.h
#pragma once
#include "stdafx.h"
#include <windows.h>
#include <process.h>
#include <Tlhelp32.h>
#include <winbase.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
void killProcessByName(WCHAR *filename);
#ifdef __cplusplus
}
#endif
main.cpp
#include "stdafx.h"
#include "snowkill.h"
#include "motion.h"
#include "info.h"
#include "flushsound.h"
#include "snowserial.h"
using namespace System;
bool on() {
return true;
}
bool off() {
return false;
}
int main()
{
listenoncommport();
for (;;) {
string onoff = checkfile();
if (onoff == "1")
{
//detected();
}
else
{
WCHAR *proccc = L"firefox.exe";
killProcessByName(proccc);
//notdetected();
}
Sleep(5000);
}
return 0;
}
You could change every instance of WCHAR to TCHAR so text setting is "generic", or as already mentioned, change the project property character set to be Unicode only.
void killProcessByName(TCHAR *filename)
/* ... */
if (_tcscmp(pEntry.szExeFile, filename) == 0) /* replaced strcmp */
/* ... */
#include <windows.h> /* needed in order to use TEXT() macro */
/* ... */
TCHAR *proccc = TEXT("firefox.exe"); /* TEXT() is a <windows.h> macro */
Use TCHAR type everywhere if the functions involved are not WCHAR specific. That would allow project setting to build either ANSI/ASCII (not set) or Unicode.
Note that Process32First and Process32Next use TCHAR.
This is mostly for legacy, since Windows 2000 and later API functions use Unicode internally, converting ANSI/ASCII to Unicode as needed, while Windows NT and older API functions use ANSI/ASCII.
However, typically many or most text files (such as source code) are ANSI/ASCII and not Unicode, and it's awkward to have to support Unicode for Windows API and then ANSI/ASCII for text files in the same program, and for those projects I use ANSI/ASCII.
By using the TCHAR based generic types, I can share common code with projects that use Unicode and with projects that use ANSI/ASCII.
The error message is clear: you have an error at this precise line:
if (strcmp(pEntry.szExeFile, filename) == 0)
Because your arguments are not of char* type as expected by strcmp but WCHAR* types. You should use wcscmp instead, which is basically the same function, but working with wchar_t* type.
szExeFile in tagPROCESSENTRY32 is declared as TCHAR, which will be a 1-byte char when compiling with Character Set set to 'Not Set' or 'Multibyte'. Set Character Set in your project settings to Use Unicode Character Set to fix the problem.
Also, use wcscmp to compare WCHAR types.

NetUserChangePassword C++

I would like to change user password on my Windows 7 PC using C++.
But when I compile it gets error:
undefined reference to 'NetUserChangePassword'
[Error] ld returned 1 exit status.`
How can I fix it?
Here is the MSDN page with the NetUserChangePassword function:
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <lm.h>
bool ChangeUserPassword(LPCWSTR OldPassword, LPCWSTR NewPassword)
{
NET_API_STATUS nStatus;
LPTSTR lp = new TCHAR[256];
DWORD dw = 256;
GetUserName(lp, &dw);
nStatus = NetUserChangePassword(NULL, lp, OldPassword, NewPassword);
delete[] lp;
if (nStatus == NERR_Success)
return true;
return false;
}
int main(int argc, char** argv)
{
LPCWSTR Old_P = L"C";
LPCWSTR New_P = L"D";
ChangeUserPassword(Old_P, New_P);
return 0;
}
I tried to link to the project the winapi32.dll in two ways
i tried to add using the project option
i tried to add following line
HINSTANCE hInst = LoadLibrary( L"C:\\Windows\\System32\\netapi32.dll ");
but i get always the same error
The requirements section of the MSDN topic you linked to states that you must link the Netapi32.lib library. That is the step that you have missed and explains the missing external error.
As to how to resolve the problem it is hard to say for sure. You are not using the MS compiler and so the #pragma approach won't work. Consult the docs for your compiler/linker to work out how to link this library.
It looks like you are using a GCC based compiler and so need to add -lnetapi32 to the options.