I'm trying to compile a C ++ program that wants to read the ports in the registry. The C ++ expert is small, I'm Java, and this is the JNI class for working with Java. Already enraged, I do not understand what he wants:
cl -I "% JAVA_HOME% \ include" -I "% JAVA_HOME% \ include \ win32" myJniClass.cpp / link / DLL Microsoft (R) C / C ++ Optimizing Compiler Version 19.00.24210 for x64 Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.00.24210.0 Copyright (C) Microsoft Corporation. All rights reserved. /out:myJniClass.dll /dll /implib:myJniClass.lib /DLL myJniClass.obj Creating library myJniClass.lib and object myJniClass.exp myJniClass.obj : error LNK2019: unresolved external symbol __imp_RegEnumValueA referenced in function Java_serialport_Serial_getSerialPortNames myJniClass.obj : error LNK2019: unresolved external symbol __imp_RegOpenKeyExA referenced in function Java_serialport_Serial_getSerialPortNames myJniClass.dll : fatal error LNK1120: 2 unresolved externals To compile, I downloaded Visual C++ Build Tools and launched Visual C++ 2015 x64 Native Build Tools Command Prompt . The source itself is verified, without errors. The code is successfully compiled via Android Studio + NDK.
Here is the problem code snippet:
HKEY phkResult; LPCSTR lpSubKey = "HARDWARE\\DEVICEMAP\\SERIALCOMM\\"; jobjectArray returnArray = NULL; //if(RegOpenKeyExA(HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_READ, &phkResult) == ERROR_SUCCESS){ if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_READ, &phkResult) == ERROR_SUCCESS){ boolean hasMoreElements = true; DWORD keysCount = 0; char valueName[256]; DWORD valueNameSize; DWORD enumResult; while(hasMoreElements){ valueNameSize = 256; //enumResult = RegEnumValueA(phkResult, keysCount, valueName, &valueNameSize, NULL, NULL, NULL, NULL); enumResult = RegEnumValue(phkResult, keysCount, valueName, &valueNameSize, NULL, NULL, NULL, NULL); if(enumResult == ERROR_SUCCESS){ keysCount++; } else if(enumResult == ERROR_NO_MORE_ITEMS){ hasMoreElements = false; } else { hasMoreElements = false; } } Specifically, the RegEnumValueA function is RegEnumValueA , and, apparently by mistake, it has become __imp_RegOpenKeyExA . This prefix comes in generated .lib and .obj. For example:
e __imp_PurgeComm __imp_SetCommBreak __imp_SetCommMask __imp_SetCommState __imp_SetCommTimeouts __imp_WaitCommEvent __imp_RegEnumValueA __imp_RegOpenKeyExA