• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "P/Invoke marshalling"

Collapse

  • ASB
    replied
    DP,

    The problem with the tools is I don't actually have any .H etc for the structure definitions. Only Cobol ones so I can't even avoid all the bleedin typing.

    I want to avoid explicit and actually do this by applying pack:=1 to the structlayoutattribute. This ensures that the members are not reordered and contiguous.

    But it does sound as though I am a bit stuffed and am going to have to produce a whole bunch of wrapper classes. Ah well.

    Leave a comment:


  • DimPrawn
    replied
    Have you tried this free tool http://www.paulyao.com/resources/tools/pinvoke.asp

    Anyway, you want Explicit not Sequential.

    http://spellcoder.com/blogs/bashmoha...2/21/4654.aspx

    I Think this will help.

    Leave a comment:


  • Weltchy
    replied
    Originally posted by ASB
    Any suggestions as to how I can do that without resorting to a custom marshaller?
    None that spring to mind, sorry!!! Would be curious to see if anyone submits an answer tho, just out of professional curiosity!!!!

    Leave a comment:


  • ASB
    started a topic P/Invoke marshalling

    P/Invoke marshalling

    Bit long and rambly but here goes:-

    I have a number of API's (about 300), they tend to use structures pretty much like this.

    <StructLayout(LayoutKind.Sequential)> _
    Friend Structure SomeReturnedData
    Friend f1 As SomeField1
    Friend f2 As SomeField2
    Friend f3 As SomeField3
    .....
    .....
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Friend Structure SomeField1
    Friend day As byte
    Friend month As byte
    Friend year As byte
    End Structure

    Now some field is the representation of a date at the other end (and there are a couple of hundred different types like this). Marshalling SomeReturnedData is not a problem, off it goes as a byte array and back it comes.

    My problem arises when I want to do this:-

    <StructLayout(LayoutKind.Sequential)> _
    Friend Structure SomeField1
    Friend day As byte
    Friend month As byte
    Friend year As byte

    'Now some internal stuff which I don't want marshalled say:
    Friend dt as DateTime

    End Structure

    The problem now of course is that the length changes from that expected. There is no <MarshalAs(IgnoreThisPlease)> type attribute.

    Obviously I have to ensure that I ensure the integrity of the internal data structures after the structure has been marshalled - a nuisance but easily enough achievable (though not automatically of course since the constructor isn't run or anything).

    Equally I can write wrappers for all the damn things, but what I want to do is encapsulate both the external and CLR representations in the structure.

    Any suggestions as to how I can do that without resorting to a custom marshaller?
Working...
X