Forums Register Login

error LNK2001 unresolved external symbol

+Pie Number of slices to send: Send
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. 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1520 times.
Similar Threads
JVM_DumpAllStacks/cl linking
JVM_DumpAllStacks/cl linking
Build a dll for JNI
JVM_DumpAllStacks/cl linking
Java: connecting to mysql [Unsolved]
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:25:09.