Jump to content

Calling External Dlls From Vp

Recommended Posts



trying to do a test.  I am trying to call a new DLL from the vbscript.


I have a basic DLL that has a class:


<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _

Public Class ComClass1


' Use the Region directive to define a section named COM Guids.

#Region "COM GUIDs"

' These GUIDs provide the COM identity for this class

' and its COM interfaces. You can generate

' these guids using guidgen.exe

Public Const ClassId As String = "7666AC25-855F-4534-BC55-27BF09D49D46"

Public Const InterfaceId As String = "54388137-8A76-491e-AA3A-853E23AC1217"

Public Const EventsId As String = "EA329A13-16A0-478d-B41F-47583A761FF2"

#End Region


Public Sub New()


End Sub


Public Function myFunction() As Integer

Return 100

End Function


End Class



I have a VBScript file that works when executed as a VBS outside of VPinball:


option explicit

dim myObject 

        Set myObject = CreateObject("MyDLL.ComClass1")
        If Err Then MsgBox"Unable to load DLL."&vbNewLine&Err.Description

Call myObject.myFunction()


when I put this code in the script for a table, it fails with "ActiveX component can't create object.


So my question is...  Do we have limitations in the code to limit the execution of external DLLs?


Edit:  oh, and if I add this line:

Dim Foo : Set Foo = CreateObject("Scripting.FileSystemObject")


that gets executed fine... 

Link to comment
Share on other sites

  • 2 months later...
  • Content Provider

a long time ago i was playing with calling other activex objects mainly the flash com


the only way i could get it to work was by manually adding the active x control to table from the insert dropdown box in editor and setting the object directly as a "shockwave flash object" then loading and calling the file using external interface class in flash that i had my swf listening for


it worked great, i could communicate to and from flash perfect but................   as soon as i saved table it would save then trying to reload file always crashed



reason i was doing this is because i was building a rom made from flash for an original table but since it didnt work i shelved it for good. maybe rascal still has the swf and instructions i made for him to try ages ago i think he managed to get it working the same as me.


just checked latest revisions of vp will crash as soon as you add the activex object to table



totally unhelpful post really but just informing you guys about an experience one weeknight a couple of years ago with vp :) 


vp is what it is, i am at piece with that concept. now i dont try to do to much playing around with external stuff anymore

Link to comment
Share on other sites

  • Content Provider

Are you sure the COM dll is getting registered with Windows properly? Register the dll with regsvr32 and in Windows 7 make sure you're running the command prompt as administrator. Damn M$ always makes things so difficult. ;)

Link to comment
Share on other sites

  • 2 months later...

just checked latest revisions of vp will crash as soon as you add the activex object to table


I know we're sort of veering off topic, but I got curious and went into the debugger to look at this.   The crash when trying to add an activex control is a simple/easy fix - there's a superfluous "delete" that was added incorrectly (it's at the wrong indent level, so maybe someone thought he found a memory leak).    It crashes when the "FREE_MEMORY" loop tries to really delete it when the dialog closes. 


Comcontrol.cpp line 68  


The crashing on load, on the other hand.   Argh!   VP doesn't bother to save the CLSID of the ActiveX object you insert!  :blink:


Here's the persist code:


bw.WriteStruct(FID(VER1), &m_d.m_v1, sizeof(Vertex2D));

    bw.WriteStruct(FID(VER2), &m_d.m_v2, sizeof(Vertex2D));

    bw.WriteBool(FID(TMON), m_d.m_tdr.m_fTimerEnabled);

    bw.WriteInt(FID(TMIN), m_d.m_tdr.m_TimerInterval);

    bw.WriteWideString(FID(PROG), m_d.m_progid);

    ISelect::SaveData(pstm, hcrypthash, hcryptkey);


There's a fifth member of "m_d" which is m_clsid.     Clsid should be the GUID of Shockwave Flash (or whatever ActiveX object you chose).    Because this is not restored, this line fails when it tries to create.


IUnknown *punk;

    hr = CoCreateInstance(m_d.m_clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (void **)&punk);

    if (SUCCEEDED(hr))


        m_pmcw->QueryInterface(IID_IAxWinHostWindow, (void**)&m_pAxWindow);

        hr = m_pmcw->ActivateAx(punk, false, pstm);



You can also see there's only a small bit of code inside the SUCCEEDED block ... the code then proceeds to try and access m_pAxWindow, which isn't valid because of the above failure to create an undefined object.   The lack of proper error handling results in the crash.


Fix here is to add persistence of m_pClsid.  No need to worry about backwards compatibility, clearly any table that uses this object is going to fail to load every time.    I tried adding it the persistence bits, and then it loads and re-instantiates the object, but there's something else missing, you can't select it in the editor.    There's probably some other bits (like the VP specific object properties - like it's name) that need to be saved as well.    Probably not too hard to fix if someone cares to use this feature.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...