Re: Cannot marshal 'return value'



You can try applying a MArshalAs(ByValArray, SIzeConst=260) to the return
type of your method signature and change the return type from char[] to
byte[]

Did that work?

---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------



"ShaunO" <ShaunO@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7C3D477B-9C16-4011-8373-E88C572F9E7D@xxxxxxxxxxxxxxxx
Thanks for the suggestion.
It errors with
A call to PInvoke function 'DLLTest!DLLTest.Q::DiskSaveFooter' has
unbalanced the stack. This is likely because the managed PInvoke signature
does not match the unmanaged target signature. Check that the calling
convention and parameters of the PInvoke signature match the target
unmanaged
signature.

I get this error message on the
IntPtr ptr = qn.DiskSaveFooter("mis1", "", "000:000"); line.

I think that Delphi's native strings are single-byte strings, whereas
.NET's are UTF-16 which may be affecting things but i get the above error
message when i define the return type as anything other than char[]

Does this help?



"G Himangi" wrote:

It may work if you define the function as

[DllImport("qn.dll",
CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]

public static extern IntPtr DiskSaveFooter(string missionname, string
qlffilename, string id);

and then.....

IntPtr ptr = qn.DiskSaveFooter("mis1", "", "000:000");
char* charArray = (char*)ptr;

this requires unsafe code though.

Or you can use Marshal.Copy to copy the contents of the ptr to a
char/byte
array.

---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and
BHOs
rapidly in .Net
---------



"ShaunO" <ShaunO@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:941ABD0B-C05C-4636-A2D9-8F247D252E54@xxxxxxxxxxxxxxxx
Hi,
I am trying to call an old Delphi .dll

// DELPHI definition (should return an array of 256 chars)
function DiskSaveFooter(missionname,qlffilename,id:pchar):TCharArray;
export;

// My C# definition
[DllImport("qn.dll",
CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]

public static extern char[] DiskSaveFooter(string missionname, string
qlffilename, string id);

// My C# Implementation
char []b = new char[256];
b = qn.DiskSaveFooter("mis1", "", "000:000");


I get the ERROR: Cannot marshal 'return value': Invalid
managed/unmanaged
type combination.

Any suggestions please?





.



Relevant Pages

  • partial analysis of vulndev-1.c
    ... two ways are used to copy a string into a buffer: ... the end of the buffer, if the string p1 is longer or equal SIZE. ... char behind the end of the buffer. ... If you don't know what a .signature is, ...
    (Vuln-Dev)
  • Re: Reply with attachment macro
    ... the Insert -> Signature menu. ... Sub ReplyWithTemplateFromOutlook() ... Dim objReply As Outlook.MailItem ... Dim strSignatureText As String ...
    (microsoft.public.outlook.program_vba)
  • Re: Question regarding fgets and new lines
    ... signature `char *getline' is simple enough that even I can ... When I designed ggets I considered that signature, ... Each error code is a unique pointer value. ... like an error message which could make it easier to track down bugs. ...
    (comp.lang.c)
  • Re: Windows application key from a vendor
    ... much private mainframe owners interested in illegal operations, ... One is a longish key that in itself contains the licence information, ... The other is a plain text licence of some sort, plus a signature or hash so ... string changes very little with small predictable changes in e.g. the date. ...
    (bit.listserv.ibm-main)
  • Verif CAPICOM generated signature in Java
    ... I have a simple text string whose digital signature has been generated ... // data to sign should reside in the content property of signeddata ... PublicKey publicKey = cert.getPublicKey; ...
    (comp.lang.java.security)