I'm really a noob in C++, but I have C++ code and when I run node-gyp build
it throws:
error LNK2001: unresolved external symbol __imp_PathQuoteSpacesA
anderror LNK2001: unresolved external symbol __imp_PathFileExistsA
.
My code:
#include <node.h>
#include <Shlwapi.h>
// Full path and name of the API
static char g_szAPI[MAX_PATH] = "";
// Handle on the QuickVision window used to comunicate
static HWND g_hWndQV = NULL;
BOOL StartQV(LPSTR lpszCmdLine)
{
STARTUPINFO siStartInfo;
PROCESS_INFORMATION processInfo;
char szCmd[1024];
DWORD retval = 0;
// First we get the installation path and name from the registry
if (!GetApiFullNameFromRegistry(g_szAPI, sizeof(g_szAPI))) {
return FALSE;
}
// If the path name has spaces, the full path name must be enclosed with quotation marks before calling CreateProcess
PathQuoteSpaces(g_szAPI); //<----throw error LNK2001: unresolved external symbol __imp_PathQuoteSpacesA
return (BOOL)retval;
}
BOOL GetApiFullNameFromRegistry(char* szAPI, DWORD dwBufLen)
{
HKEY hKey=0;
LONG retval= -1;
BOOL Flag = FALSE;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_KEY, 0, KEY_QUERY_VALUE|KEY_WOW64_32KEY, &hKey))
{
retval = RegQueryValueEx(hKey, "MjExec", NULL, NULL, (LPBYTE)szAPI, &dwBufLen);
RegCloseKey(hKey);
}
Flag = ERROR_SUCCESS == retval && dwBufLen != 0;
if (Flag) {
Flag = PathFileExists(szAPI); //<----throw error LNK2001: unresolved external symbol __imp_PathFileExistsA
}
return Flag;
}
When I comment the code that throws an error, the code is built successfully.
It was necessary to add #pragma comment(lib, "Shlwapi.lib")
at the top of the script to solve the problem
Result:
#pragma comment(lib, "Shlwapi.lib") // <-- adding this
#include <node.h>
#include <Shlwapi.h>
// Full path and name of the API
static char g_szAPI[MAX_PATH] = "";
// Handle on the QuickVision window used to comunicate
static HWND g_hWndQV = NULL;
BOOL StartQV(LPSTR lpszCmdLine)
{
STARTUPINFO siStartInfo;
PROCESS_INFORMATION processInfo;
char szCmd[1024];
DWORD retval = 0;
// First we get the installation path and name from the registry
if (!GetApiFullNameFromRegistry(g_szAPI, sizeof(g_szAPI))) {
return FALSE;
}
// If the path name has spaces, the full path name must be enclosed with quotation marks before calling CreateProcess
PathQuoteSpaces(g_szAPI); // <-- now it works fine
return (BOOL)retval;
}
BOOL GetApiFullNameFromRegistry(char* szAPI, DWORD dwBufLen)
{
HKEY hKey=0;
LONG retval= -1;
BOOL Flag = FALSE;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_KEY, 0, KEY_QUERY_VALUE|KEY_WOW64_32KEY, &hKey))
{
retval = RegQueryValueEx(hKey, "MjExec", NULL, NULL, (LPBYTE)szAPI, &dwBufLen);
RegCloseKey(hKey);
}
Flag = ERROR_SUCCESS == retval && dwBufLen != 0;
if (Flag) {
Flag = PathFileExists(szAPI); // <-- now it works fine
}
return Flag;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.