Valhalla Legends Forums Archive | .NET Platform | MarshallAsAttribute

AuthorMessageTime
Grok
As Any ... used to be valid in VB6, not valid in VB.NET .. documentation says to use MarshallAsAttribute to fix this.

Declare Function KGI_CNMInitServices Lib "wkgi32.dll" (ByVal bBlocked As Long, <MarshallAsAttribute(UnmanagedType.AsAny)> ByVal pNode As Object, ByVal perr As Long) As Boolean

However, "Type MarshallAsAttribute" is not defined" is the error I get.

Imports System.Attribute does not help, still not defined.  The declare is in a standard module, Module1.vb.  What do I need to import so that MarshallAsAttribute is defined?

Bigger question, how are these situations (C DLLs, memory blocks, pointers) handled in .NET?
December 7, 2005, 2:23 PM
Myndfyr
You need to Imports System.Runtime.InteropServices.MarshalAsAttribute.
December 7, 2005, 4:04 PM
Grok
Doesn't work.

[code]
Imports System.Runtime.InteropServices.MarshalAsAttribute

Module VBKGI
    '***********************************************
    '          GENERAL FUNCTIONS
    '***********************************************

    Declare Function KGI_CNMInitServices Lib "wkgi32.dll" (ByVal bBlocked As Long, <MarshallAsAttribute(UnmanagedType.AsAny)> ByVal pNode As Object, ByVal perr As Long) As Boolean
End Module
[/code]

Still underlines MarshallAsAttribute and says it is not defined.
December 7, 2005, 4:18 PM
Myndfyr
Because Marshal is spelled with one L.

You should use:

Imports System.Runtime.InteropServices

to include all the types in that namespace, because your next compiler error will involve the undefined type "UnmanagedType".

Also, depending on the use of pNode, you should probably be able to use it as an IntPtr, or as the structure that the function will be called with.  It's very odd to see you wanting to pass a managed object out as data into a function.

Finally, you should consider not using a Declare, but instead using the DllImport attribute:
[code]
<DllImport("wkgi32.dll")>_
Public Shared Function KGI_CNMInitServices(ByVal bBlocked As Boolean, _
<MarshalAs(UnmanagedType.AsAny)> ByVal pNode As Object, _
ByVal pErr As Long) As Boolean
[/code]

Want to contract me to do this work for you Grok?  :P
December 7, 2005, 4:39 PM
Grok
[quote author=MyndFyre link=topic=13447.msg136720#msg136720 date=1133973578]Want to contract me to do this work for you Grok?  :P[/quote]

Why do you ask?
December 7, 2005, 9:02 PM
Grok
Found what I need in MSDN topic:  Consuming Unmanaged DLL Functions
December 7, 2005, 9:41 PM
Myndfyr
[quote author=Grok link=topic=13447.msg136733#msg136733 date=1133989376]
[quote author=MyndFyre link=topic=13447.msg136720#msg136720 date=1133973578]Want to contract me to do this work for you Grok?  :P[/quote]

Why do you ask?
[/quote]
Because I wouldn't mind contract work.  :)
December 7, 2005, 10:54 PM

Search