• Welcome to Valhalla Legends Archive.
 

MarshallAsAttribute

Started by Grok, December 07, 2005, 08:23 AM

Previous topic - Next topic

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?

MyndFyre

You need to Imports System.Runtime.InteropServices.MarshalAsAttribute.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Grok

Doesn't work.


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


Still underlines MarshallAsAttribute and says it is not defined.

MyndFyre

#3
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:

<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


Want to contract me to do this work for you Grok?  :P
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Grok

Quote from: MyndFyre on December 07, 2005, 10:39 AMWant to contract me to do this work for you Grok?  :P

Why do you ask?

Grok

Found what I need in MSDN topic:  Consuming Unmanaged DLL Functions

MyndFyre

Quote from: Grok on December 07, 2005, 03:02 PM
Quote from: MyndFyre on December 07, 2005, 10:39 AMWant to contract me to do this work for you Grok?  :P

Why do you ask?
Because I wouldn't mind contract work.  :)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.