我用VC调用DLL中的函数,出现"内存不能为written"的问题
具体是这样的,现在手头上有一个Fnthex32.dll,以下是函数说明,有点乱:
* Function in FNTHEX.DLL:
* GETFONTHEX() - Get bitmap in hex code of specific out
* string and font to buffer.
* Parameter:
* 1) LPSTR outStr, // output string
* 2) LPSTR lfFaceName, // Windows font name
* 3) LPSTR outstrname // output string name
* 4) short int lfOrientation, // clock-wish Orientation: 0,90,180,270
* 5) short int lfHeight, // font height
* 6) short int lfWidth, // font width, always set to 0
* 7) short int lfBold, // bold font style
* 8) short int lfItalic, // italic font style
* 9) LPSTR hexBuf // buffer to receive hex codes,
* size must set to 21K.
* Return : Byte count of buffer contents if successful, otherwise <= 0
*
* Note : 1) Before program to call function GETFONTHEX() in FNTHEX32.DLL,
* Statement must be added to declare it in the call program.
* 2) Function name GETFONTHEX() must in upper case.
* 3) Before function GETFONTHEX() is called, the buffer that is equal
* to 21K must to allocate first.
* 4) The return of GETFONTHEX() is greate than 0 if function call is
* successful, and result of Chinese data is stored in 21K buffer.
* The total number of byte output in buffer is return by GETNFONTHEX().
* 5) Printer driver "Generic / Text Only" must be set for
* label printing under Windows 32 bit environment.
我不确知道以上信息是C/C++还是其他语言的,关于调用Fnthex32中的GETFONTHEX函数网上很多VB/DELPHI方法,但我需要的是C/C++,因为我主要是用JAVA通过C++去使用这个DLL,以下是我的一个测试用的C程序代码:
#include "stdlib.h"
#include "string.h"
#include "windows.h"
#include "stdio.h"
#include "iostream.h"
int main(){
typedef int (_stdcall* FNC1)(LPSTR,LPSTR,LPSTR,short int,short int,short int,short int,short int,LPSTR);
HINSTANCE hDLL=::LoadLibrary("d:\\BIN\\Fnthex32.dll");
if(hDLL!=NULL){
FNC1 fun=(FNC1)::GetProcAddress(hDLL,"GETFONTHEX");
if(fun==0){
printf("no such function found.\n");
FreeLibrary(hDLL);
}else
{
int i;
i=125;
//char* buf = new char[21504];
//LPSTR buf = "";
LPSTR buf = (LPSTR)malloc(21*1024);
//i = fun("中文","宋体","chnstr01",0,50,0,1,0,buf);
cout<<&buf<<endl;
FreeLibrary(hDLL);
}
}
return 0;
}
如果不把"i = fun("中文","宋体","chnstr01",0,50,0,1,0,buf);"这行注释掉就会提示内存不能WRITTEN之类的,怎么解决呢?谢谢大家.