[quoted text, click to view] "Steve Richter" <StephenRichter@gmail.com> wrote in message
news:1173155219.298389.112910@8g2000cwh.googlegroups.com...
> On Mar 5, 5:30 pm, Tamas Demjen <tdem...@yahoo.com> wrote:
>> Steve Richter wrote:
>> > Cannot marshal 'parameter #7': Pointers cannot reference marshaled
>> > structures. Use ByRef instead.
>>
>> You must have a name collision. You're probably not calling the
>> unmanaged Win32 FormatMessage, but another function that happens to have
>> the same name.
>>
>> Your code compiles for me without any errors (VC++2005 SP1). Just try to
>> put it into an empty unit, like this:
>>
>> // FormatMessage.cpp
>> #include "stdafx.h"
>> #include <windows.h>
>>
>> using namespace System;
>>
>> String^ FormatMessage( DWORD rc )
>> <snip> // your code unchanged
>>
>> If that still doesn't work, remove #include "stdafx.h" and disable
>> precompiled headers for that unit.
>>
>> Tom
>
> thanks for the help. The solution ended up being a change in the
> project from "pure MSIL CLR support" to what I guess is a more
> flexible "clr support".
>
> now I am reading in the archives that I cant call my C++ code from C#
> unless the c++ is pure MSIL? The FormatMessage API bombed on the last
That is most assuredly false. MSIL vs native code does have implications
for security (native code cannot run without full trust), but C# can call
into mixed assemblies just fine.
[quoted text, click to view] > argument, a VARARG or whatever it is called. How do I know what
> unmanaged code can be included in a "pure MSIL" project and what cant?
In pure MSIL, every API call has to be converted to a DllImport statement.
If there's no conversion, it won't work.
In the case of FormatMessage, it's not that MSIL can't make the call, it's
that the compiler hasn't enough information to construct the P/Invoke
signature. However, you could do that yourself, just as doing P/Invoke from
C# (
http://www.pinvoke.net/default.aspx/kernel32/FormatMessage.html)
[quoted text, click to view] >
> -Steve
>
>