tags:

views:

232

answers:

3

a cpp file:

#include <iostream>
#include <jni.h>
#include "Hello.h"
#include "windows.h"
#include "stdafx.h"

typedef void(__stdcall *Print_)();

int main(){

  HINSTANCE hDll;   //DLL句柄 
  Print_ print_;  //函数指针
  hDll = LoadLibrary("Hello.dll");

  if (hDll != NULL)
   { 

    print_ = (Print_)GetProcAddress(hDll,"Java_Hello_sayHello@8"); 
    if(print_!=NULL)
    {

     print_();
    } 
    FreeLibrary(hDll); 
   }
 return 0;

}

//there is something wrong, it prints: http://i983.photobucket.com/albums/ae311/keatingWang/c_wrong.png 未声明的标识符 means : Undeclared identifier

+10  A: 

Consider the macro:

#define HINSTANCE "hDll"

and its use:

HINSTANCE hDll;   //DLL句柄 

after preprocessing it would look like:

"hDll" hDll;

which clearly is an error as it makes hDll undeclared as "hDll" is not a valid type.

codaddict
delete #define HINSTANCE "hDll"there still is something wrong
Keating Wang
Something specific ? Tell us what's wrong.
nos
+2  A: 

remove

#define HINSTANCE "hDLL"

To remove C4627 warning, move up #include "stdafx.h" to the top (to be the first #include) as indicated by Mike Dinsdale's answer. This will probably solve error for LoadLibrary, GetProcAddress, and FreeLibrary:

#include "stdafx.h" // moved up
#include <iostream>
#include <jni.h>
#include "Hello.h"
#include "windows.h"
afriza
+2  A: 

Could it be a pre-compiled header issue? With some project settings VC++ will skip stuff before the #include "stdafx.h", which I think might be the cause of the C4627 warnings you're getting. Have you tried moving #include "stdafx.h" before your other #includes?

Mike Dinsdale