UserLibs using VB.NET

Blitz3D Forums/Blitz3D Programming/UserLibs using VB.NET

PetBom(Posted 2004) [#1]
Has anybody used VB.NET to create userlibs for usage from Blitz3D. I have problem passing parameters to and from the userlib.

I've manipulated the IL code based on the great article in the code archives by Defiance (Thanks btw, great stuff):

Using The Microsoft .NET Framework with Blitz

But I can't get passing of parameters to work. So what I looking for is someone that has is experienced in using VB.NET together with Blitz3D on a more advanced level. I can manage to get an "Hello World" app running, but as soon as I try getting a bit more advanced (multiple function parametrs, returning cocatunated strings etc.) I run into problem. My guess is that it has to do with VB.NET's rather loose definition of data types. But I really need some pointers where to go next, for more information.

Note that I do not have problems like this with C#. Everything works beautifully. But I really want to get my VB.NET code working as well, since I have quite a lot of rather nifty graphic routrines developed in that specific language (mainly GUI controls in GDI++)

Anyone?

//PetBom


Sweenie(Posted 2004) [#2]
I was fiddling with this as well.
But all I managed to accomplish was an "application shutdown function"... that is, as soon as I called a function in the .NET DLL, blitz shut down without any errormessage or anything.
VB6 did the same thing.

And all the function did was adding two integers together and returned the result.


PetBom(Posted 2004) [#3]
Well I really don't have a problem passing things from the VB.NET DLL to blitz. My problems start when I need to pass parameters from blitz to a method in the DLL. Calling methods and returning data to blitz is not a problem. It's when I need to pass parameters _to_ the method the problems start. I'm pretty certain that it's a data type problem. I just can't figure out what. Looking at the IL code I cannot se any obvious faults. There is one thing that worries me though. It seems that the order of the methods in the class gets reversed in the IL code if you use VB.NET as aposed to C#. This shouldn't matter (check the Defiance article above) if you set up the v-Tables correctly. But maybe something else is reversed as well, say paramaters to a function. I can't see it happening, but then I'm not an expert on IL-code.

How did you edit the IL code? I found this yesterday which is kind of helpful when 'un-managing' the .NET DLL (by hacking the IL-code):

ILIDE

It's a simple editor for IL code. It does syntax highlighting and has built in support for de-compiling and compiling (DLL -> IL and IL -> DLL)

Your issues with VB6 probably is another problem, since VB6 is all unmanaged code

I'm going to dig a bit deeper and try to report my findings.

Or maybe there is someone out there that actually has managed to pass parametrs to VB.NET userlibs?

//PetBom


Deldy(Posted 2004) [#4]
I dont know if it will help, but I saw somewhere that and Integer in a un-managed is the same as a VB-Short.

So try to replace your paremteres into Shorts. (Will maybe help)


Sweenie(Posted 2004) [#5]
no, what I meant with VB6 is that when I call the .net dll from VB6 it shuts down aswell, just like blitz do.

It seems I have a similar problem as what I try do to is to pass two integers to the .net DLL.


Robert(Posted 2004) [#6]
Neither VB6 nor VB.NET can make normal DLLs. They are ActiveX controls which are a totally different and rather more complex beast.


Sweenie(Posted 2004) [#7]
Perhaps not VB6, but with the method above(see link in the first post) you can make the .NET DLL expose it's functions as if it were unmanaged code.
I haven't got it working yet, but Defiance who wrote the article has got it working.


PetBom(Posted 2004) [#8]
Neither VB6 nor VB.NET can make normal DLLs. They are ActiveX controls which are a totally different and rather more complex beast.


Not entirely true Robert. As for VB6 the dll's created actually are COM compontents (which AcitveX controls are a subset of) that interacts with other applications using a COM intreface/COM interop.

And as for .NET, Microsoft has actually dropped the term ActiveX, since the introtuction of the .NET framework. Whatever language you use everything will be parsed to IL and CRL, so it makes more sense to speak about managed an unmanaged code. So you could say that VB.NET cant create unmanaged code (but as we've seen, it can!) but that doesn't really make the resulting DLL an ActiveX control.

Sweenie - Ok i thought you were calling a VB6 dll from blitz. BTW have you done any tests with C#? As I said I've done some and everything has worked fine. Have you tried doing a call from VB6 to an unmanaged (By IL manipulating) C#.NET dll? If you can do that I guess that it's safe to say that some other components of the IL need tweaking in the case of VB.NET code.

I could send you my VB.NET dll if you'd like. As I have mentioned it does not work all the way. But at least it does not shut down blitz. The only thing that does not work is the input parameters. It returns data to blitz quite happily. It would be interesting to see if you can run it.

//PetBom


Sweenie(Posted 2004) [#9]
Sure, check my profile for the emailadress.


Sweenie(Posted 2004) [#10]
Do you know what calling convention a .NET DLL use?


Sweenie(Posted 2004) [#11]
hmm, I successfully managed to pass a string and return it.
look at this piece of IL-code...
    .method public instance string  SayHi(string Name) cil managed
    {
      // Code size       16 (0x10)
      .maxstack  2
      .locals init (string V_0)
	.vtentry 1:1
	.export [1] as SayHi
      IL_0000:  ldstr      "Hej "
      IL_0005:  ldarg.1
      IL_0006:  call       string [mscorlib]System.String::Concat(string,
                                                                  string)
      IL_000b:  stloc.0
      IL_000c:  br.s       IL_000e

      IL_000e:  ldloc.0
      IL_000f:  ret
    } // end of method Foo::SayHi

  } // end of class Foo



I changed the row that says...
IL_0005: ldarg.1
to
IL_0005: ldarg.0

The question is why the VB.NET DLL(or the IL-assembler) tries to get the stringparameter from position 1

[Swedish]
Vad dumt det känns att prata engelska med någon som man vet är svensk. :)
[/Swedish]


PetBom(Posted 2004) [#12]
Hmm...You're right. It seems that my VB IL does tha same thing. I tries to pass parameter 1 (Which does not exist). Really weird! There must be something in the IL code that we are missing. I've got a colleague that is something of a IL/CRL wizard. I must discuss this with him and see if he can give some pointers.

But I realize that if you actually have to debug the IL code it's not worth the effort, messing with VB. It would be faster to convert the code to C#...

[Swedish]
Hehe! Själv är jag ganska van att snacka engelska med svenskar. Fler och fler företag har engelska som corp. language och all kommunikation och dokumentation skall vara på engeska (Jag jobbar i konsult branschen). Men jag kan hålla med om att det är lite fånigt. Jag visste inte att du var svensk. Kul!
[/Swedish]

//PetBom


Kanati(Posted 2004) [#13]
[quote]Neither VB6 nor VB.NET can make normal DLLs. They are ActiveX controls which are a totally different and rather more complex beast.




Not entirely true Robert. As for VB6 the dll's created actually are COM compontents (which AcitveX controls are a subset of) that interacts with other applications using a COM intreface/COM interop.
[/quote]

VB6: Can create standard windows DLLs. You have to use a 3rd party tool to do it. My BlitzData and BlitzPrinter dlls are both created with VB6.

VB.NET: You can force standard windows DLLs, but it takes some doing.


LostCargo(Posted 2005) [#14]
has anyone made any headway?
i have spent some time tooling up in vb.net and suddenly realized the dealing with D3d sux. way to much granularity for what i want to do.

Is there any instance where someone has succeeded in passing a variable to a dll function and getting a response?


LostCargo(Posted 2005) [#15]
has anyone made headway?