接口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先去吃饭.....下午哪个有空的讨论讨论啊,谢谢大家!~

解决方案 »

  1.   

    error C2664: 'cal_width' : cannot convert parameter 2 from 'unsigned short ** ' to 'unsigned char *'这个错误和你贴的代码好像不太一样呢
    应该只有在cal_width(24,&str)时才应该报这个错?BSTR是UNICODE下的,每个单位2字节,而unsigned char *是一个字节的。
      

  2.   

    str 是地址,*str才是字符串
      

  3.   

    error C2664: 'cal_width' : cannot convert parameter 2 from 'unsigned short ** ' to 'unsigned char *'这个错误和你贴的代码好像不太一样呢
    应该只有在cal_width(24,&str)时才应该报这个错?BSTR是UNICODE下的,每个单位2字节,而unsigned char *是一个字节的。
    =======================
    真的是这个错误....BSTR的错误该怎么改正呢?
    我才学VC不久
    可能数据类型搞得不是很清楚....
      

  4.   

    这个程序我是想 把网页传过来的数据通过接口print(long n1, BSTR *str)接收把n1格式化输入到文件
    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后有些数据类型不懂用....
    哪个来帮帮看看
      

  5.   

    BSTR 实质就为WCHAR * 也就是宽字节指针,你右键GO TO DEFENITION看看就知道了先获取*str的值(类型为WCHAR),然后用WideCharToMultiByte转换后,就可以传进cal_width了试下下面的,(随便写的,没测试)char newStr[100];
    WideCharToMultiByte(CP_ACP, 0, newStr, -1, *str, strlen(*str), NULL,NULL);cal_width(24, newStr);
      

  6.   

    不好意思,弄错了
    写了个你参考下
    #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 );
    }
      

  7.   

    int  cal_width(int font,unsigned char *str);函数定义是这样.....是要unsigned char
    上面的不得捏
      

  8.   

    我现在把接口变成Cfun::print(int n1, char *str)了,可能这样好点....还有哪个来只只招
      

  9.   

    unsigned char newstr[500];
    sprintf((char *)newstr, "%s",str);
    发现我改成这个形式就编译过了.....但是现在不能测试....
    <html>
    <script language="javascript">
    var myobj = new ActiveX("adddd.Cfun");
    myobj.fun(123,456);
    </script>
    </html>
    这个是测试脚本,但是老是出错
    哪个来看看哈
      

  10.   

    cal_width(24,str)
    改为cal_width(24,W2A(str))
    试下
      

  11.   

    cal_width(24,W2A(str))
    不行的话,用cal_width(24,OLE2A(str))
      

  12.   

    呵呵,从char *到 unsigned char*转换没什么危险吧,向上操作啊,去掉结束符0不得了char *testStr1 = "123456";
    printf( "%s", (unsigned char*)testStr1);路过高人请指点...
      

  13.   

    编译是通过了...
    但是调用不行:(
    <html>
    <script language="javascript">
    var myobj = new ActiveX("adddd.Cfun");
    myobj.fun(123,456);
    </script>
    </html>
    这个脚本写错了那里....
      

  14.   

    写了一个脚本测试
    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>
    但是就是不成功调用.....
    哪个来指点指点