Shoutbox

[Resolved] Talking to VB. - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Resolved] Talking to VB. (/showthread.php?tid=62676)

[Resolved] Talking to VB. by Tails on 07-06-2006 at 03:01 PM

I'm new to Plus! and JS.

I'm pretty skilled with VB 6 & VB.Net however.

Is there a way to have all the events aviable in VB, maybe an API call or function?

Or do i have to manually make a "translator" for each event and argument etc etc?

How could i go about doing this any way? I don't know any direct way to communicate from JS to VB... well fast any way, i'm sure i could read/write to a file... but that's just not practicle.

Also (Not related to the post) When i was doing the mini tutorial that you can download for JS, i found a problem; When i try to make a xml form come up (i don't know the correct term for it). It would not show. I tried restarting MSN and the script and i followed it exactly, i even tried to get it to show up when a msg was recieved (by looking at the code from other scripts), but nothing worked. I'm still trouble shooting this problem however.


RE: Talking to VB. by matty on 07-06-2006 at 03:03 PM

Create an ActiveX DLL then call it as an ActiveXObject in the scripts.


RE: Talking to VB. by Tails on 07-06-2006 at 03:25 PM

What do i put in this DLL?

So i have to manually make all the events and stuff in the dll?

What JS do i use?


RE: Talking to VB. by matty on 07-06-2006 at 03:40 PM

quote:
Originally posted by Tails
Also (Not related to the post) When i was doing the mini tutorial that you can download for JS, i found a problem; When i try to make a xml form come up (i don't know the correct term for it). It would not show. I tried restarting MSN and the script and i followed it exactly, i even tried to get it to show up when a msg was recieved (by looking at the code from other scripts), but nothing worked. I'm still trouble shooting this problem however.
Make sure the XML file is saved as Unicode
Check out this example I made : Matty's reply to Cannot CreateChildWnd

quote:
Originally posted by Tails
What do i put in this DLL?
Whatever you want?

quote:
Originally posted by Tails
So i have to manually make all the events and stuff in the dll?
You code whatever events you want it to do. Like have a MessageBox appear.

quote:
Originally posted by Tails
What JS do i use?
Remeber also you need to register your DLL using regsvr32 or by calling the Exported function from the DLL called DllRegisterServer (i think its called).
code:
function OnEvent_Initialize(bMessengerStart){
    var MyActiveXObject = new ActiveXObhect('Projectname.Classname');
}

RE: Talking to VB. by Tails on 07-06-2006 at 04:02 PM

ok, thanks for that!

I Will create a DLL and when it's finished i may post it on this site, with script included of course.

User defined objects and forms (from JS) will be a problem for me however and the DLL may not include them.

My bad too, i missed that! I didn't save it as unicode, it was saved as the default (ANSI). It now works :D:D:D:P


RE: RE: Talking to VB. by mathieumg on 07-08-2006 at 05:00 AM

quote:
Originally posted by Matty

code:
function OnEvent_Initialize(bMessengerStart){
    var MyActiveXObject = new ActiveXObject('Projectname.Classname');
}


Corrected typo ;)
RE: Talking to VB. by Tails on 07-08-2006 at 11:49 AM

This is going to need 2 actives X files...

One that communicates and translates from JS.

The other will be added to a VB project and used to relay the commands from the JS active X.

They'll communicate with the send message api or somthing like that.


RE: Talking to VB. by CookieRevised on 07-08-2006 at 11:54 AM

Maybe if you explain in great detail what your plugin/script will do, we could help you more.

As I see it now, you're making it way, and I mean waaaaaaay :D, too complicated and unneeded.


RE: Talking to VB. by Tails on 07-08-2006 at 12:30 PM

lol, I'm trying to make it so that i can use VB instead of JS. I don't know much about JS i doubt it's as powerful as VB (well i know JS is good and probebly as powerful, but in a different way). VB has a good editor and all that as well, plus it's easier to link up to other programs and manipulate strings and all that stuff.

My plan in the end is to make a bot with VB that my msn can use, but i guess it will be better just to make the momma load so i can use the same code if i want to make something else with msn/vb later as well.

I don't think JS is good to do something like this in.


RE: Talking to VB. by CookieRevised on 07-08-2006 at 01:06 PM

I see... well it can perfectly be done in JScript though, just as easy as it is in VB and you wouldn't have all the overhead and stuff...

Note: you only need 1 ActiveX DLL (yuor 'bot') and the wrapper script if you still want to continue to do this in VB6; not two activex DLLs. Also you don't need the sendmessage API, events in your activex dll can be triggered directly from within JScript and vice versa.

In fact, you don't need to make this event driven actually. Your activex dll could simply be the "core engine", processing the given text (manipulating the text and stuff) and outputting the reaction, while your JScript script simply calls the procedure from that "core engine" to process a string. No need for events syncronization between JScript and the activexdll in that way.


RE: Talking to VB. by Tails on 07-09-2006 at 04:24 AM

I have no idea how this is to be done.

This way sounds alot better and alot less complecated then my way!

But i don't know how to make JS raise an event (i supose a class would be better and having public events that JS triggers, with some parameters that are passed when the event is triggered such as text). The ActiveX will work this way.


RE: Talking to VB. by CookieRevised on 07-09-2006 at 10:27 AM

Forget about events and stuff, just as in VB6, in the scripts the events are triggered automatically. Everything is done right inside the scripts. All you need to do is make some functions to handle your text.

Read and study the scripting documentation, examples are shown there.

Also, you can find examples in the scripting database.

eg: Some basic JScript code you need:

code:
function OnEvent_SigninReady(sEmail) {
    var oMyBot = new ActiveXObject('Your.ActiveX');
}

function OnEvent_ChatWndReceiveMessage(pChatWnd, sOrigin, sMessage, nMessageKind) {
    Debug.Trace('Chat window: ' + pChatWnd);
    Debug.Trace('Contact name: ' + sOrigin);
    Debug.Trace('Message recieved: ' + sMessage);
    Debug.Trace('Message type: ' + nMessageKind);
    if (sOrigin != Messenger.MyName) {
        var ReplyMessage = oMyBot.ProcedureToHandleText(sMessage);
        pChatWnd.SendMessage(ReplyMessage);
    }
}
and in your VB6 code all you need is the procedure "ProcedureToHandleText" inside a public class module to handle the text and which will return a string to send back to the convo.

And as you can see, it is actually quite easy to replace
code:
var ReplyMessage = oMyBot.ProcedureToHandleText(sMessage);
with your text manipulating routines in JScript itself. You don't need VB6 at all. JScript isn't that hard...

RE: Talking to VB. by Griffo on 07-09-2006 at 11:04 AM

I've been trying to work with DLL's too, not much luck though!

I've tried making a basic script to simply display some test from a DLL.

SCRIPT:

code:
function OnEvent_Initialize(MessengerStart)
{
var MyActiveXObject = new ActiveXObject('Project1.Class1');
Debug.Trace(MyActiveXObject.ShowMyText);
}

VB DLL:
code:
Public Function ShowMyText()
ShowMyText = "Hello World!"
End Function

I am using the code above, but I keep getting the following error..."
code:
Script is starting
Script is now loaded and ready
Function called: OnEvent_Initialize
Error: Wrong number of arguments or invalid property assignment.
       Line: 4. Code: -2146827838.
Function OnEvent_Initialize returned an error. Code: -2147352567

Any idea what I am doing wrong?

Thanks :)
RE: Talking to VB. by CookieRevised on 07-09-2006 at 11:11 AM

The VB DLL must be an ActiveX DLL, this means your exposed functions need to be in a public class module. Look at the plugin documentation for Plus!3. Plugins are ActiveX DLLs. Example provided in the docs.


RE: Talking to VB. by matty on 07-09-2006 at 02:27 PM

And you also have to regsvr32 the dll so it is registered on the computer.


RE: Talking to VB. by Griffo on 07-09-2006 at 03:56 PM

Yup covered all that, still no joy! :( Anyone got an example at all?


RE: Talking to VB. by matty on 07-09-2006 at 04:19 PM

quote:
Originally posted by Griffo
code:
function OnEvent_Initialize(MessengerStart)
{
var MyActiveXObject = new ActiveXObject('Project1.Class1');
Debug.Trace(MyActiveXObject.ShowMyText);
}

It should be written as MyActiveXObject.ShowMyText()
code:
function OnEvent_Initialize(MessengerStart)
{
var MyActiveXObject = new ActiveXObject('Project1.Class1');
Debug.Trace(MyActiveXObject.ShowMyText());
}
quote:
Originally posted by Griffo
code:
Public Function ShowMyText()
ShowMyText = "Hello World!"
End Function

When declaring ShowMyText it should return a string
code:
Public Function ShowMyText() As String
ShowMyText = "Hello World!"
End Function

Here you go.
RE: Talking to VB. by Griffo on 07-09-2006 at 08:32 PM

Thanks a lot mate, works perfectly now! :D


RE: Talking to VB. by Tails on 07-09-2006 at 10:54 PM

Script is starting
Script is now loaded and ready
Function called: OnEvent_Initialize
Error: Automation server can't create object.
       Line: 5. Code: -2146827859.
Function OnEvent_Initialize returned an error. Code: -2147352567

It can't create your ActiveX. I tried registering it manually as well. I used the project you provided and tried my own.

EDIT *** The way i got it to work was to comment the register and unregister lines and create my own bat file.

Thank you for this, your way is soo much better.:D:P


RE: [Resolved] Talking to VB. by cooldude_i06 on 07-09-2006 at 11:30 PM

Also remember that when you make changes to your dll, and even unregister and re-register it, your script won't be able to use the new dll UNLESS:

1. you restart messenger or
2. save the dll with a different project name and use that when creating ActiveXObject