首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#中dll引用有关问题

2012-01-23 
c#中dll引用问题有一个fnthex32.dll查看不到里边函数GETFONTHEX的参数了,只有一个dephi的例子可以正确执行

c#中dll引用问题
有一个fnthex32.dll   查看不到里边函数GETFONTHEX的参数了,只有一个dephi的例子可以正确执行,我想把这个方法用C#实现,出现了访问内存错误和运行库错误.下面是dephi里的代码

function   GETFONTHEX(chnstr:   string;   fontname:   string;   orient:   integer;   height:   integer;   width:   integer;   bold:   integer;   italic:   integer;   hexbuf:   string):   integer;   stdcall;   external   'fnthex32.dll ';

function   PrtChnStr(x,   y:   integer;   fontname:   string;   height,   xmf,   ymf:   integer;   chnstr:   string):   string;
var
    buf,   ret:   string;
    count:   integer;
begin
    result   :=   ' ';
    setlength(buf,   21   *   1024);
    count   :=   GETFONTHEX(chnstr,   fontname,   0,   height,   0,   1,   0,   buf);
    if   count   >   0   then
    begin
        ret   :=   Copy(buf,   1,   count);
        result   :=   ret;
    end;
end;

我贴上我用C#改的  
                [DllImport( "fnthex32.dll ",CharSet   =   CharSet.Ansi)]

                public   static   extern   int   GETFONTHEX(
                              string   chnstr,
                              string   fontname,
                              int   orient,
                              int   height,
                              int   width,
                              int     bold,
                              int     italic,
                              ref     string   hexbuf);

调用:
                private   string   GetCharset()
                {
       
                      char   []strHex   =   new   char[21*1024];

                      string   test   =   new   string(strHex);   ;
                   
                        int   count;
                        count   =   GETFONTHEX(   "测试 "   ,   "宋体 ",   0,   5,   30,   0,   0,   ref   test   );
                        if   (count   >   0)


                        {
                                return   test.Substring(0,count)+   "^FO10,140^XGOUTSTR01,1,2^FS ";
                        }
                        return   " ";
                }

我感觉是   ref     string   hexbuf参数的问题   ,把ref   去掉可以执行,但返回不了GETFONTHEX里的执行情况,就是test里的数据没变,现在不知道怎么写这个函数了,请大大们帮忙看看,谢谢了.

[解决办法]
看不懂DELPHI...
但是REF的话应该就是传进处理后输出吧

[解决办法]
先看看,帮顶一下
[解决办法]
是不是.net的内存安全机制引起的,hexbuf应该是操作托管堆中的内存地址,跟C++的实际地址不一样
[解决办法]
是不是没有名空间的定义?
[解决办法]
ref string hexbuf

改成 ref buty [] hexbuf
[解决办法]
ref string hexbuf
改为StringBuilder hexbuf

传入参数前县给StringBuilder 分配内存

StringBuilder hexbuf = new StringBuilder(255);

热点排行