#include "MakeJNI.h"
#include <windows.h>
#include <direct.h>
#include <string.h>

JNIEXPORT jint JNICALL Java_MakeJNI_JNIMake( JNIEnv *env, jclass cla2s, jstring s, jlong nClumn,  jlong nErr, jlong nHLRatio,jlong nHeight) {
HINSTANCE hInst;
typedef void  (__stdcall *MAKE)(unsigned char* ucData, long nDataLen, char* szBmpFileName, long nClumn, long nErr, long nHLRatio,long nHeight);

MAKE Make;


char szFileName[MAX_PATH];

//产生正确的文件名
ZeroMemory(szFileName, MAX_PATH);

getcwd(szFileName, MAX_PATH);

strcat(szFileName, "\\temp.bmp");

if(s==NULL) 
	return 1;

//DLL载入，获取函数句柄
hInst = LoadLibrary("MakePDF417.dll");
if(!hInst)
	{
		exit(0);
	}
Make = (MAKE)GetProcAddress(hInst, "Make");


//生成条码
int len = 256*2;
char* szStr = new char[len];
wchar_t *w_buffer = new wchar_t[256];
wcscpy(w_buffer,env->GetStringChars(s,0));
env->ReleaseStringChars(s,w_buffer);
WideCharToMultiByte(CP_ACP, 0, w_buffer, 1024, szStr, len, NULL, NULL);
Make((unsigned char*)szStr, strlen(szStr), szFileName, nClumn, nErr, nHLRatio,nHeight);
FreeLibrary(hInst);

return 0;
}



JNIEXPORT jint JNICALL Java_MakeJNI_JNISetColorDepth(JNIEnv *, jclass, jint nDepth){
HINSTANCE hInst;
typedef int  (__stdcall *SETCOLORDEPTH)(int nDepth);
SETCOLORDEPTH SetColorDepth;
hInst = LoadLibrary("MakePDF417.dll");
if(!hInst)
	{
		exit(0);
	}
SetColorDepth = (SETCOLORDEPTH)GetProcAddress(hInst, "SetColorDepth");
SetColorDepth(nDepth);
FreeLibrary(hInst);

return 0;

}


JNIEXPORT jint JNICALL Java_MakeJNI_JNIGetColorDepth(JNIEnv *, jclass){
HINSTANCE hInst;
typedef int  (__stdcall *GETCOLORDEPTH)();
GETCOLORDEPTH GetColorDepth;
hInst = LoadLibrary("MakePDF417.dll");
if(!hInst)
	{
		exit(0);
	}
GetColorDepth = (GETCOLORDEPTH)GetProcAddress(hInst, "GetColorDepth");
int n=GetColorDepth();
FreeLibrary(hInst);
return n;


}
