一个cpp文件:
#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;
}
Run Code Online (Sandbox Code Playgroud)
//有错误,打印出来: http ://i983.photobucket.com/albums/ae311/keatingWang/c_wrong.png未声明的标识符表示:未声明的标识符
cod*_*ict 10
考虑宏:
#define HINSTANCE "hDll"
Run Code Online (Sandbox Code Playgroud)
及其用途:
HINSTANCE hDll; //DLL??
Run Code Online (Sandbox Code Playgroud)
预处理后,它看起来像:
"hDll" hDll;
Run Code Online (Sandbox Code Playgroud)
这显然是一个错误,因为它是hDll
未声明的,因为"hDll"
它不是一个有效的类型.