接口char filepath[80]="c:\\test\\";
HANDLE hCom;
void WritePrint(char* str);
void openfile();
void open_font_file();
void tran_to_zf(int font,unsigned char *str,
int prnx0,int prny0,int xdot0,int ydot0);
void close_font_file();
void ser_gb_big5(char gb[] ,char *b5_fp);
long std(unsigned char, unsigned char);
int spc(unsigned char, unsigned char);
int cal_width(int font,unsigned char *str);Cfun::print(long n1, BSTR *str)
{
DWORD dwError;
hCom = CreateFile("c:\\test\\1.txt",GENERIC_WRITE|GENERIC_READ,0,NULL, OPEN_EXISTING,0,NULL);
if(hCom==INVALID_HANDLE_VALUE)
{
MessageBox(NULL,"SetCommTimeout error","Error",MB_OK);
dwError=GetLastError();
}
char tmp1[30]="Hello World!";
WritePrint(tmp1); open_font_file();
sprintf((char *)length,"%05d,",cal_width(24,str)*24);
sprintf((char *)width, "%03d,",cal_width(24,str));
tran_to_zf(24,str,70,0,1,1);
}Cfun::WritePrint(char *str)
{
unsigned long dwLen;
int len;
len = strlen(str);
WriteFile(hCom,str,len,&dwLen,NULL);
}Cfun::open_font_file()
{
sprintf(opstr,"%s%s",filepath,"2.txt");
if((stdf24=fopen(opstr,"rb")) == NULL )
{
//printf("file is not easit!");
MessageBox("NO Ducment");
exit(0);
}
}
错误信息:error C2664: 'cal_width' : cannot convert parameter 2 from 'unsigned short ** ' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\msn\test\adddd\fun.cpp(83) : error C2664: 'cal_width' : cannot convert parameter 2 from 'unsigned short ** ' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\msn\test\adddd\fun.cpp(84) : error C2664: 'tran_to_zf' : cannot convert parameter 2 from 'unsigned short ** ' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\msn\test\adddd\fun.cpp(216) : error C2556: 'int __thiscall Cfun::std(unsigned char,unsigned char)' : overloaded function differs only by return type from 'long __thiscall Cfun::std(unsigned char,unsigned char)'
d:\msn\test\adddd\fun.h(46) : see declaration of 'std'
D:\msn\test\adddd\fun.cpp(216) : error C2371: 'std' : redefinition; different basic types
d:\msn\test\adddd\fun.h(46) : see declaration of 'std'
D:\msn\test\adddd\fun.cpp(452) : error C2264: 'std' : error in function definition or declaration; function not called先去吃饭.....下午哪个有空的讨论讨论啊,谢谢大家!~
HANDLE hCom;
void WritePrint(char* str);
void openfile();
void open_font_file();
void tran_to_zf(int font,unsigned char *str,
int prnx0,int prny0,int xdot0,int ydot0);
void close_font_file();
void ser_gb_big5(char gb[] ,char *b5_fp);
long std(unsigned char, unsigned char);
int spc(unsigned char, unsigned char);
int cal_width(int font,unsigned char *str);Cfun::print(long n1, BSTR *str)
{
DWORD dwError;
hCom = CreateFile("c:\\test\\1.txt",GENERIC_WRITE|GENERIC_READ,0,NULL, OPEN_EXISTING,0,NULL);
if(hCom==INVALID_HANDLE_VALUE)
{
MessageBox(NULL,"SetCommTimeout error","Error",MB_OK);
dwError=GetLastError();
}
char tmp1[30]="Hello World!";
WritePrint(tmp1); open_font_file();
sprintf((char *)length,"%05d,",cal_width(24,str)*24);
sprintf((char *)width, "%03d,",cal_width(24,str));
tran_to_zf(24,str,70,0,1,1);
}Cfun::WritePrint(char *str)
{
unsigned long dwLen;
int len;
len = strlen(str);
WriteFile(hCom,str,len,&dwLen,NULL);
}Cfun::open_font_file()
{
sprintf(opstr,"%s%s",filepath,"2.txt");
if((stdf24=fopen(opstr,"rb")) == NULL )
{
//printf("file is not easit!");
MessageBox("NO Ducment");
exit(0);
}
}
错误信息:error C2664: 'cal_width' : cannot convert parameter 2 from 'unsigned short ** ' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\msn\test\adddd\fun.cpp(83) : error C2664: 'cal_width' : cannot convert parameter 2 from 'unsigned short ** ' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\msn\test\adddd\fun.cpp(84) : error C2664: 'tran_to_zf' : cannot convert parameter 2 from 'unsigned short ** ' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\msn\test\adddd\fun.cpp(216) : error C2556: 'int __thiscall Cfun::std(unsigned char,unsigned char)' : overloaded function differs only by return type from 'long __thiscall Cfun::std(unsigned char,unsigned char)'
d:\msn\test\adddd\fun.h(46) : see declaration of 'std'
D:\msn\test\adddd\fun.cpp(216) : error C2371: 'std' : redefinition; different basic types
d:\msn\test\adddd\fun.h(46) : see declaration of 'std'
D:\msn\test\adddd\fun.cpp(452) : error C2264: 'std' : error in function definition or declaration; function not called先去吃饭.....下午哪个有空的讨论讨论啊,谢谢大家!~
应该只有在cal_width(24,&str)时才应该报这个错?BSTR是UNICODE下的,每个单位2字节,而unsigned char *是一个字节的。
应该只有在cal_width(24,&str)时才应该报这个错?BSTR是UNICODE下的,每个单位2字节,而unsigned char *是一个字节的。
=======================
真的是这个错误....BSTR的错误该怎么改正呢?
我才学VC不久
可能数据类型搞得不是很清楚....
sprintf(dwWrite,"BARCODE %d,%d,%cEAN8%c,76,1,0,1,2,%c%s%c\r\n",70,27,0x22,0x22,0x22,spcode,0x22);
WritePrint(dwWrite);把str字符串转换成这个形式后 sprintf((char *)length,"%05d,",cal_width(24,str)*24);
sprintf((char *)width, "%03d,",cal_width(24,str));
打印出来我用C实现了函数,但是放到activex后有些数据类型不懂用....
哪个来帮帮看看
WideCharToMultiByte(CP_ACP, 0, newStr, -1, *str, strlen(*str), NULL,NULL);cal_width(24, newStr);
写了个你参考下
#include<stdio.h>
#include<tchar.h>
#include<windows.h>
void main()
{
char *str = "test";
WCHAR *wstr = L"test";
BSTR *bstr;
BSTR bstrSrc= ::SysAllocString( L"test" );
bstr = &bstrSrc;
char newStr[100];
WideCharToMultiByte(CP_ACP, 0, *bstr, -1, newStr, 101, NULL,NULL);
printf( "%s", newStr );
}
上面的不得捏
sprintf((char *)newstr, "%s",str);
发现我改成这个形式就编译过了.....但是现在不能测试....
<html>
<script language="javascript">
var myobj = new ActiveX("adddd.Cfun");
myobj.fun(123,456);
</script>
</html>
这个是测试脚本,但是老是出错
哪个来看看哈
改为cal_width(24,W2A(str))
试下
不行的话,用cal_width(24,OLE2A(str))
printf( "%s", (unsigned char*)testStr1);路过高人请指点...
但是调用不行:(
<html>
<script language="javascript">
var myobj = new ActiveX("adddd.Cfun");
myobj.fun(123,456);
</script>
</html>
这个脚本写错了那里....
STDMETHODIMP Cfun::add(int n1, int n2)
{
// TODO: Add your implementation code here
DWORD dwError; hCom = CreateFile("c:\\test\\1.txt",GENERIC_WRITE|GENERIC_READ,0,NULL, OPEN_EXISTING,0,NULL);
if(hCom==INVALID_HANDLE_VALUE)
{
MessageBox(NULL,"SetCommTimeout error","Error",MB_OK);
dwError=GetLastError();
} int n3;
n3 = n1 + n2; unsigned long dwLen;
WriteFile(hCom,&n3,sizeof(n3),&dwLen,NULL); return S_OK;
}脚本:
<html>
<script language="javascript">
var myobj = new ActiveX("addtest.Cfun");
myobj.add(123,456);
</script>
</html>
但是就是不成功调用.....
哪个来指点指点