News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Marshaling and Attributes

Started by Zen, July 23, 2016, 05:42:27 AM

Previous topic - Next topic

Zen

Here's a question that's mainly for you theoretical physicists and cosmologists (do I have an awful lot of annoying questions, or what ???):
And, I should preface it by saying that I only have an extremely bleak comprehension of the topic, so, I'm probably asking the wrong question, or phrasing it in the wrong context, or,...typically,...I'm just completely wrong about everything,...:dazzled:

Anyway,...the topic is Marshaling (as in):
Overview of Marshaling in C++, MSDN
Interop Marshaling, MSDN
Marshaling Data with COM Interop, MSDN
.NET - COM Interoperability, CodeProject, 2003

...And, what I'm interested in is: what is the best method for writing either: a COM Callable Wrapper, or, Stub and Proxy interoperability Architecture interfaces that will connect and manage elements of native (MASM assembly) code, and either COM or .NET components (or, more likely both).

...And, as a bonus question: How can I reliably implement attributes (which are compiler features, I think),...maybe, as a really complex MACRO (or, hierarchy of MACROS) ??? As examples: IDL Attributes, MSDN,...and,...COM Attributes, MSDN.

rrr314159

From the cosmology point of view the answer is very simple. Just wait a while. In 5 billion years the sun will become a red giant, Earth will be destroyed, and none of this will matter. You may object: human race will survive on other planets, circling other suns. Well in that case wait a bit longer (100 billion years maybe), Universe is expected to die a "heat death". When there are no molecules left within light years of each other, again, you won't have to worry about this. Perhaps that's too long a time frame? Well, within a mere 100 million years we'll probably be hit by a large meteor, destroying all Windows computers, so that takes care of that problem.

Bottom line, from the theoretical cosmology point of view, Marshaling can simply be ignored. Seems the easiest solution, doesn't it?
I am NaN ;)

hutch--

 :biggrin:

But will the last computers be running Windows Multidimensional Universe Ultimate  ?

GoneFishing

So only computers with Windows operating system will be destroyed ?
I'm on the safe side  having  Linux on my machine  :biggrin:


rrr314159

Most theoretical cosmologists don't believe in a benevolent God. But I'm sure they'd all agree that IF such a person exists, then only Windows computers will be destroyed. Linux computers will be preserved in a giant Ark. Unfortunately the very existence of Windows pretty much proves we live in a random, meaningless Universe that doesn't care about us at all. In that case expect the worst: possibly ONLY Windows Multidimensional Universe Ultimate version 10 computers will survive! Linux and Windows 7 pro computers will be right at ground zero when the meteor hits.

Bottom line, given this pessimistic view, what difference does Marshaling really make? Might as well just have a cold beer, watch the tube, wait for death, and vote for Trump.
I am NaN ;)

Zen

WELL,...that's what I get for asking a question like that. :dazzled:
Quote from: GOD...from the theoretical cosmology point of view, Marshaling can simply be ignored,...

...RRR314159 (and, HUTCH),...you guys are hilarious !!! Apparently,...God DOES have a sense of humor,...
...This is kinda disappointing,...though,...from the perspective of my current project...
I can see that indiscriminate, non-denominational, neutrino-based Marshaling is the only rational course of action here,... :dazzled:

rrr314159

With any luck the best course of action is to wait for someone who knows about marshalling (unlike myself) to provide some useful information :P
I am NaN ;)

jj2007

Quote from: rrr314159 on July 23, 2016, 06:54:44 AMFrom the cosmology point of view the answer is very simple. Just wait a while. In 5 billion years the sun will become a red giant...

Thank you for putting this into perspective :t I've always wondered why right-clicking on a file takes ages, i.e. Billions of cycles to ask COM for displaying a list of options... it's the cosmology, stupid :icon_redface:

anunitu

Quote from: rrr314159 on July 23, 2016, 07:41:30 AM
Most theoretical cosmologists don't believe in a benevolent God. But I'm sure they'd all agree that IF such a person exists, then only Windows computers will be destroyed. Linux computers will be preserved in a giant Ark. Unfortunately the very existence of Windows pretty much proves we live in a random, meaningless Universe that doesn't care about us at all. In that case expect the worst: possibly ONLY Windows Multidimensional Universe Ultimate version 10 computers will survive! Linux and Windows 7 pro computers will be right at ground zero when the meteor hits.

Bottom line, given this pessimistic view, what difference does Marshaling really make? Might as well just have a cold beer, watch the tube, wait for death, and vote for Trump.


I am liking the cold beer and watch the tube part of your platform,BUT I would use Trump as a first test to stop the giant meteor,if he does not survive,nothing lost..grabs another beer and watches South park as I wait for the end...

Zen

#9
    ...For those of you that are not: COSMOLOGISTS,...

    I've found lots of information about Marshaling (both COM and .NET),...I can post these if there's any interest,...:dazzled:
    But,...I've also made two MAJOR discoveries: 


    • I'm an Idiot.
    • My defunct application: COM CoreFluxWarp provides lots of information about .NET Framework classes (actually their implemented COM interfaces) that expose .NET methods for creating attributes and Marshaling attributes. You just have to scroll down to each entry that has mscoree.dll as it's COM In-Proc server, and double-click the entry.
For example: (these are the associated registry keys for the In-Proc server -- mscoree.dll -- System.Runtime.InteropServices namespace)

[.NET Framework Class]   
COM Class CLSID:    {96A058CD-FAF7-386C-85BF-E47F00C81795}
    Value:    [Default] = System.Runtime.InteropServices.InAttribute
SubKey:    Implemented Categories
SubKey:    InprocServer32
    Value:    Class = System.Runtime.InteropServices.InAttribute
    Value:     = mscoree.dll
    Value:    ThreadingModel = Both
    Value:    Assembly = mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    Value:    RuntimeVersion = v1.1.4322
SubKey:    ProgId
    Value:     = System.Runtime.InteropServices.InAttribute


...and,...

[.NET Framework Class]   
COM Class CLSID:    {FDB2DC94-B5A0-3702-AE84-BBFA752ACB36}
    Value:    [Default] = System.Runtime.InteropServices.OutAttribute
SubKey:    Implemented Categories
SubKey:    InprocServer32
    Value:    Assembly = mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    Value:    Class = System.Runtime.InteropServices.OutAttribute
    Value:     = mscoree.dll
    Value:    RuntimeVersion = v1.1.4322
    Value:    ThreadingModel = Both
SubKey:    ProgId
    Value:     = System.Runtime.InteropServices.OutAttribute


...And,...yes,...these two interface vtables can be instantiated with either: CoCreateInstance or a COM Class Moniker,...

GoneFishing

See google book : .NET 2.0 Interoperability Recipes: A Problem-Solution Approach by Bruce Bukovics
Chapter 7 describes In / Out attributes

Zen

In the January, 2008 issue of MSDN Magazine there is an article: Marshaling between Managed and Unmanaged Code, by Yi Zhang and Xiaoying Guo, which describes how [InAttribute] and [OutAttribute] control marshaling between unmanaged and managed code. 
Quote from: Yi Zhang and Xiaoying Guo...When applying to method parameters and return values, these attributes control marshaling direction, so they're known as directional attributes. [InAttribute] tells the CLR to marshal data from the caller to the callee at the beginning of the call, while [OutAttribute] tells the CLR to marshal back from the callee to the caller upon return. Both the caller and the callee can be either unmanaged or managed code,...
...These attributes would be fairly easy to implement in MASM assembly,...just by following the conventions of normal .NET marshaling,...
Some of the other .NET attributes, like [PreserveSigAttribute], [StructLayoutAttribute] and [MarshalAs(UnmanagedType], I have no idea how to implement in MASM assembly,...
Here is a listing of: .NET Framework Attributes, MSDN
Here is an article about .NET attributes: Defining and Using Custom Attribute Classes in C#, Code Magazine
...And, here is another article:Creating and Using Attributes in Your .NET Application, CodeProject

GoneFishing

Quote from: Zen on July 26, 2016, 04:19:13 AM
In the January, 2008 issue of MSDN Magazine there is an article: Marshaling between Managed and Unmanaged Code, by Yi Zhang and Xiaoying Guo, which describes how [InAttribute] and [OutAttribute] control marshaling between unmanaged and managed code. 
...

Got it  here

Maybe in  October when I hopefully  get back to programming I'll continue this challenging quest

anunitu

The whole Marshaling thing smacks of the nanny state of matter,and bigger and more intrusive atoms.(yes that was a little humor,very little)

mabdelouahab

Hi Zen

Quote from: Zen on July 26, 2016, 04:19:13 AM
...These attributes would be fairly easy to implement in MASM assembly,...just by following the conventions of normal .NET marshaling,...
Some of the other .NET attributes, like [PreserveSigAttribute], [StructLayoutAttribute] and [MarshalAs(UnmanagedType], I have no idea how to implement in MASM assembly,...
Here is a listing of: .NET Framework Attributes, MSDN
Here is an article about .NET attributes: Defining and Using Custom Attribute Classes in C#, Code Magazine
...And, here is another article:Creating and Using Attributes in Your .NET Application, CodeProject

It varies depending on the purpose of the use  it
for example:
use it in  managed code when you need to be  specific regarding how your .NET type will be exposed to COM, or when you need to be  specific regarding how COM Class will be import from COM
System.Runtime.InteropServices Attribute Equivalent to COM IDL Def

{Managed:System.Runtime.InteropServices.InAttribute} = {UnManaged:COM IDL parametre attribut [In] }
{Managed:System.Runtime.InteropServices.OUTAttribute}={UnManaged:COM IDL parametre attribut [Out] }

Also you can use System.Runtime.InteropServices Attribute in UnManaged code (like MASM) if you want to create Dynamic Assembly (Define Dynamic Assembly,TypeBuilder , MethodBuilder ,... ) or if you want to create Delegate