Re: Help me!!!

From: Dmitriy Lapshin [C# / .NET MVP] (x-code_at_no-spam-please.hotpop.com)
Date: 02/24/05


Date: Thu, 24 Feb 2005 13:51:55 +0200

Hi,

I've seen numerous advices to use StringBuilder whenever you pass strings by
ref. You can try this in your example.

-- 
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
"morice" <chulaiguo@163.com> wrote in message 
news:OOB8tHhGFHA.2416@TK2MSFTNGP14.phx.gbl...
>I have writen a dll(EmrCmprs.dll) using c++ and a function in this DLL:
>
> __declspec(dllexport) long EmrDecompress( char *pcCompressData /*in*/,
>           long lCompressDataSize/*in*/,
>           char **ppcRawData/*unicode out*/,
>           long *plRawDataSize/*out*/ )
> {
>  ...
> }
>
> Then,i invoke the function(EmrDecompress) in dotframework:
>
>  [DllImport("EmrCmprs.dll")]
>  private static  extern int EmrDecompress_BYTE(
>   byte[] pSrc,
>   int iSrcLen,
>   [MarshalAs(UnmanagedType.LPWStr)]
>   ref string pDst,
>   ref int iDstLen );
>
>  private void Test_Click(object sender, System.EventArgs e)
>  {
>   byte[] pSrc ;
>   int iSrcLen;
>   string pDst = null;
>   int iDstLen = 0;
>
>   try
>   {
>        // -- open file
>       FileStream fsRead = new FileStream(@"c:\chu0.DAT" ,
>       FileMode.Open , FileAccess.Read ,
>       FileShare.ReadWrite);
>
>       // -- get data
>       iSrcLen = (int)fsRead.Length;
>       pSrc = new byte[fsRead.Length];
>       fsRead.Read(pSrc , 0 , (int)fsRead.Length);
>
>       // -- close file
>       fsRead.Close();
>
>
>      int iResult = EmrDecompress(pSrc,iSrcLen,ref pDst,ref iDstLen);
>
>
>       if(iResult != 0)
>      {
>         throw new Exception("Decompress is failed!");
>       }
>    }
>   catch (Exception ex)
>   {
>     throw ex;
>   }
>  }
>
> But i get error pDst and right iDstLen!
> (In C++,the function of EmrDecompress do right thing.)
> I think the following parameter is not right:
> [MarshalAs(UnmanagedType.LPWStr)]
>   ref string pDst
> but how to modify it ?
> I try again and again,but failed!
>
> Can you help me?
>
> Thanks in advance!
>
> Morice
>
>
> 


Relevant Pages

  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • Kernighan and Pikes "Beautiful" Code
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • Re: local path
    ... public static extern int WNetGetUniversalName( ... ref StringBuilder lpBuffer, ... public string ConvertLocalPathToUnc( ... ref buffer, ref size); ...
    (microsoft.public.dotnet.framework)
  • Re: local path
    ... public static extern int WNetGetUniversalName( ... ref StringBuilder lpBuffer, ... public string ConvertLocalPathToUnc( ... ref buffer, ref size); ...
    (microsoft.public.dotnet.framework)
  • RE: Controling Modal Dialogs (Solution)
    ... doesn't return until the 'modal' browser returns. ... string varOptions) ... public void DocumentComplete ... int rc = winDisp.Invoke(rgDispId, ref guid, 0, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)