all groups > dotnet interop > july 2003 >
You're in the

dotnet interop

group:

DllImport / Call a Sub that is in a Class


DllImport / Call a Sub that is in a Class Johannes Hammersen
7/29/2003 1:43:59 PM
dotnet interop:
Hi,
I'm trying to access a Sub that is in a Class of an Dll:
TheClass.TheSub()

But I can not figure out how to tell DllImport that the Sub is inside the
class:

<DllImport("C:\Programme\I_R_DLL\I_R_RecipeDllPrj.dll",
EntryPoint:="TheSub")> Public Shared Sub TheSubTest()

Will not work, it tells me:
Unable to find an entry point named TheSub in DLL
C:\Programme\I_R_DLL\I_R_RecipeDllPrj.dll.

So how do I let it know that "TheSub" is withing the Class "TheClass"?

Thank you for any help

Johannes Hammersen

Re: DllImport / Call a Sub that is in a Class Johannes Hammersen
7/29/2003 4:56:08 PM
Oh and:
I can't use "Add Reference..." -> "Com" because
tlbimp.exe creates the wrong Parameters for some of the Functions. I tried
correcting
them by hand.
(http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q306801) But I
don't seem to have to much luck with that.
So I was hoping I could use DllImport or Lib to manually declare the
Methods. That way I could change the parameters.

Thanks for any Help
Johannes


"Johannes Hammersen" <Johannes.Hammersen@x75.net> schrieb im Newsbeitrag
news:OH1B1acVDHA.2272@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

Re: DllImport / Call a Sub that is in a Class Mattias Sjögren
7/29/2003 5:41:00 PM
Johannes,

[quoted text, click to view]

Can you be a bit more specific regarding which parameters were
imported incorrectly? Perhaps we can help you fix them.


[quoted text, click to view]

You can't do that for COM interface methods.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Re: DllImport / Call a Sub that is in a Class Johannes Hammersen
7/29/2003 5:59:04 PM
[quoted text, click to view]
That would be great.
Ok, one of the Functions (COMFindRecipes) should take a String with the path
to a file, and two Arrays of Singles and some more Parameters.
But when using Add Reference -> Com ...
It changed the two arrays to simple Singles.

So I used tlbimp.exe and ildasm to make an Il File of the Dll.
Than changed the following from:
.method public hidebysig newslot virtual abstract
instance void COMFindRecipes([in] string& marshal( bstr)
ActiveFileName,
[in] float32& TargetRflValues,
[in] float32& SubstrateRflValues,
[in] float32 GlossValue,
[in][out] int32& NoOfRecipesReady,
[in][out] int32& RetValue) runtime
managed internalcall
To: (replaced & with [])
.method public hidebysig newslot virtual abstract
instance void COMFindRecipes([in] string& marshal( bstr)
ActiveFileName,
[in] float32[] TargetRflValues,
[in] float32[] SubstrateRflValues,
[in] float32 GlossValue,
[in][out] int32& NoOfRecipesReady,
[in][out] int32& RetValue) runtime
managed internalcall

and did the same again a few lines down lower in the IL Code.
That seemed to help, the new Dll want's two arrays now. But when I try to
use the Dll, I get a msgbox telling me that there is no file at the position
of: "ActiveFileName" (1st Parameter). I read somewere (don't know were, been
trying to solve this for a few days) that my kind of String is not the type
of String the Dll wants. So that's where I gave up on this approch and tried
to useing Dllimport so I could tell It what kind of string, or use
stringbuilder.

I have an C++ example on how to talk to the Dll if that helps.

Thank you for any help,
this is driving me nuts! And I don't have a clue on what to do.

Johannes Hammersen

[quoted text, click to view]

Re: DllImport / Call a Sub that is in a Class Mattias Sjögren
7/30/2003 12:46:43 AM
Johannes,

[quoted text, click to view]

You should also add

marshal([])

to the array parameters to ensure that the arrays are marshaled as
C-style arrays rather than SAFEARRAYs which is the default for COM
interop.

....
[in] float32[] marshal([]) TargetRflValues,
[in] float32[] marshal([]) SubstrateRflValues,
....


[quoted text, click to view]

It must say that the string is a BSTR in the type library, otherwise
the type library importer wouldn't have decorated the parameter with
marshal(bstr). And I assume that the existing typelib is correct.


[quoted text, click to view]

Yep, that would help if the above changes doesn't make it work. Feel
free to mail it to me if it's too big to post here.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
AddThis Social Bookmark Button