Page 1 of 1

Weird problem with VB.NET plugin creation

Posted: December 27th, 2007, 2:48 pm
by shinobi_h2o
Hi there, guys.

I'm trying to write a plugin with VB.NET that would get the telemetry data from GTR2.

There's a little application and an OCX version created by a guy that goes by the nick Nye. This application (and it's OCX version) grabs some data from GTR2's shared memory area, and you can use the OCX to write your own program.

First problem: the OCX seems to be event-driven. As I see, the Smartie plugin can't be made with it, because Smartie's calls to the DLL will never sync with the events. Then I made a small tray app that keeps receiving these events and updating the variables, but I couldn't get it to pass the values to another application (in this case, the Smartie DLL).

So the application now copies the data to the clipboard, and my Smartie DLL tries to read the clipboard.

Second problem: I can't get the plugin to get the data, sepparate the variables (they're sepparated with a "chr(124)") and return it as a string.

Even before the "return" statement, I get problems.
Here's my code:

Code: Select all

        Try
            Dim xData As Object = System.Windows.Forms.Clipboard.GetDataObject
            Dim Dades As Array = Split(xData, Chr(124))
            Dim dades2 As String = Dades(param1)
            Return dades2
        Catch ex As Exception
            Return ex.Message
        End Try
And it always returns "Converstion from type 'DataObject' to type 'String' is not valid."

The funniest part is that I have this in my tray application (in the same function that handles the event. It copies to the clipboard, and right after, executes the same snippet as above, only instead of "return", it writes to a textbox):

Code: Select all

        Try
            Dim xData As Object = System.Windows.Forms.Clipboard.GetDataObject
            Dim Dades As Array = Split(xData, Chr(124))
            Dim dades2 As String = Dades(2)
            Me.TextBox1.Text = dades2
        Catch ex As Exception
            Me.TextBox1.Text = ex.Message
        End Try
And guess what: it DOES write to the textbox.


Any suggestions?
Also, does anybody know of a simple yet efficient (and, why not, more ellegant) way to do true IPC instead of this clipboard workaround (without involving TPC/HTTP and network stuff - direct memmory-like)?


P.S.: The output from the clipboard is something like this: (I added some newlines because it would break the page layout, but it's a long single-lined string)
Player Name|38,28391|38,12056|2|1338,833|7999,751|1|1|49,97912|-1|0|-1|0|20,16783|20,20591|20,21888|20,21918
|20,20641|20,16698|20,17661|20,20854|20,20793|20,20847|20,20823|20,1764|168,0618|168,0618|168,0618
|168,0618|0|0|0|0|0|0|0|0|SilverstoneGP|0|4|0|0|0|0|21,44589|20|20,30797|20,30797|20,23023|20,23044|BMW M3 GTR|[/code]

Posted: December 27th, 2007, 7:02 pm
by limbo
Your problem seems to be somewhere with the data types...

Check the returned data from the clipboard, try to check the conversion in each step.

I also recommend to use the registry instead the clipboard... use the getsetting and savesetting commands to avoid conflicts with other applications on the clipboard.. :D

Some practical now
Try to use Split(xData, "|")
and one question?
Have to tried to convert the ex.Message to string before return it?

Posted: December 28th, 2007, 3:54 pm
by shinobi_h2o
Hey, Limbo! What a honor! :D:D

I love your plugins, especially those TinyBar and SplitTitle!

See, I'm sure the problem is this:

Code: Select all

            Dim xData As Object = System.Windows.Forms.Clipboard.GetDataObject
            Dim Dades As Array = Split(xData, Chr(124))
It would be kindda pain in the neck to debug all of this, because I would have to declare all these variables as globals and all, but I'm pretty sure the problem happens here.
The ex.Message is already a simplified version of ex.ToString, so that's not the problem... Heheh

I also tryied to use "|" instead of chr(124), but no go.
About writing it to the registry, wouldn't it cause an impact on performance?

I've uploaded the older version (the one that throws an exception), but I managed to use the registry and it's working now, though I'm not reeeeally happy with using the registry. lol

I think the registry should be banished, but anyways... lol
At least I can already play with my telemetry in my LCD! :D:D:D


Thanks a lot for the help, Limbo! I'll try and make a more ellegant version now. :D:D:D

Have a great new year! =))


P.S.: Attachment contains the binaries and source code (in VB.NET v1.1).

Posted: December 28th, 2007, 10:27 pm
by limbo
Keep up the good work friend...

I'll check the code (just curious) when I finish my installation of VS 2008... (new package!!! new features, I hope) :D
BTW registry access doesn't slow down the systems (nowdays :D )

Posted: December 29th, 2007, 3:21 am
by shinobi_h2o
Hey there!
I'm using your "round" plugin a lot in my screens. Maybe I'll add some rounding built-in my code, but I'm too lazy to do that right now. lol

I'm running VS.NET 1.1. I didn't like that much the changes from VB.NET 1.1 to 2.0. Only the database changes were good, the rest only confused me. lol
I'll try this VS.NET 2008 to see if it's good! Heheh


Thanks for all the help, bro!

Keep up your great work! =)



Oh! Just a little suggestion! You should describe more what your plugins do without the user having to download them! lol