Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

error LNK2001 unresolved external symbol  RSS feed

 
suwandy wong
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
First of all, thank you very much in advance
I have a problem regarding the Java program with Native Methods. The compilation command that I used in DOS:
cL -Ic:\jdk1.3.1_02\include �Ic:\jdk1.3.1_02\include\win32\ -LD HelloWorldImp.cpp �Fehello.dll.
The above command gives me this error:
HelloWorldImp.obj : error LNK2001: unresolved external symbol __imp__GetUserNameA@8
Hello.dll : fatal error LNK1120: 1 unresolved externals
The codes were written to check for the windows login and return a flag whether has this person logon successfully with his/her password. However, the above error arises as I was trying to extract out the username with this command:
GetUserName(chrUserName, &dwUserName);
When I run this code from C++ only without JNI, it works perfectly.
My Path, include and lib was correctly define
Path:
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin; C:\Program Files\Microsoft Visual Studio\VC98\bin
Include:
C:\Program Files\Microsoft Visual Studio\VC98\atl\include;C:\Program Files\Microsoft Visual Studio\VC98\mfc\include;C:\Program Files\Microsoft Visual Studio\VC98\include
Lib:
C:\Program Files\Microsoft Visual Studio\VC98\mfc\lib;C:\Program Files\Microsoft Visual Studio\VC98\lib
Below is the whole code of C++ combine with JNI:

#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
#include <iostream.h>
#include <windows.h>// Header for Win32 API
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
HANDLE token;
// Variable for user name
char chrUserName[100];
// Variable for computer name
char chrCompName[100];
// Variable for username length
DWORD dwUserName = sizeof(chrUserName);
// Variable for compname length
DWORD dwCompName = sizeof(chrCompName);
// Get User Name
GetUserName(chrUserName, &dwUserName);
// Get Computer Name
GetComputerName(chrCompName, &dwCompName);
cout << "computer " << chrCompName << ".\n\n";
// Display Information
cout << "User " << chrUserName << " is currently logged onto computer " << chrCompName << ".\n\n";
/*
// Return control to OS
cout << "Login Status = " << LogonUser("Rianto Mulia", "domain", "test", LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT, &token) << "\n\n";
*/
return;
}
Thank you in advance for your help, I really appreciate it. 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!