unk1911 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I am new to the community. Not sure if this is the right place to post this question but I decided to try anyway.

I am trying to interface with the Bloomberg system to pull some data from it. The process works from a VBA script which invokes their API's. I am pretty sure the blpdatax.dll DLL implements the API calls.

I was trying to do the equivalent of the following VBA code in Perl:

Dim objDataControl As BLP_DATA_CTRLLib.BlpData
Set objDataControl = new BlpData

Thusly:

my $bloom0 = Win32::OLE->new('BLP_DATA_CTRLLib.BlpData');
my $bloom1 = Win32::OLE->new('BlpData');

When I run the code, I get the:

Win32::OLE(0.1502) "Invalid Class String" error

I made sure that the .dll was registered with regsvr32.exe. If anyone has any code samples or any ideas on how to get past this error, I would great appreciate it.

  • Comment on Accessing Bloomberg API's via Win32::OLE

Replies are listed 'Best First'.
Re: Accessing Bloomberg API's via Win32::OLE
by Courage (Parson) on Jan 07, 2005 at 15:09 UTC
    DLL API is completely different with OLE.

    In order to use Win32::OLE you need for that application to provide IDispatch COM interface.

    If it does, you will go, otherwise you can't do this with Win32::OLE, but you will still be able to do it another way.
    but this is completely different story.

Re: Accessing Bloomberg API's via Win32::OLE
by holli (Abbot) on Jan 07, 2005 at 16:06 UTC
    You will have to find out the correct ProgId (same as Class String). This is mostly not the same as the name of the class you want to use.

    You can find that ID by searching the registry.

    When a COM DLL is registered, ProgID-entries are placed in the registry to allow clients and the COM libraries to locate, create, and use classes in the COM DLL. The registry entries for COM classes are located in HKEY_CLASSES_ROOT in the system registry.

    The ProgID keys are located at:

    \HKEY_CLASSES_ROOT\<progid>
    For example, if you wanted to create a DataBase-Jet-Object from the Jet-engine (DAO, same as MS Access uses), the ProgID for for the DAO-Classes is located at \HKEY_CLASSES_ROOT\DAO.DBEngine.36 (Version 3.6)

    In VBScript this would be written as

    set jet = CreateObject ("DAO.DBEngine.36") set db = jet.OpenDatabase("path\to\database")
    So you have to start "regedit" and search for ProgId that belongs to the DLL you want to use.

    Update:

    The ProgID has one subkey called CLSID. This contains the CLSID for the class, and this is how a ProgID can be mapped to the CLSID that is then used to instantiate a COM class.

Re: Accessing Bloomberg API's via Win32::OLE
by jplindstrom (Monsignor) on Jan 07, 2005 at 15:52 UTC
    If it's an ordinary Win32 API interface in the DLL like Courage thinks, try using the Win32::API module.

    However, if it works with VBA it sounds like it's an ActiveX object.

    You don't say which line breaks. I can imagine either of them will create the object for you, but not both.

    Try to browse the OLE "class" in an OLE browser (hit Alt-F11 in e.g. Word, then open the OLE browser. There is also supposed to be one in the ActiveState Perl distro as well, but I never got that to work (hints welcome)).

    /J

Re: Accessing Bloomberg API's via Win32::OLE
by digger (Friar) on Jan 07, 2005 at 16:06 UTC
    I think you are looking for Win32:API. With this module, you can do something like:
    use Win32::API; my $objDataControl = Win32::API->new("blpdatax", "<c prototype of func +tion>"); my $bloomData = $objDataControl->Call();
    You can do this for each API call you want to import into your script. Of course, this means you have to know what the C prototype of the API call you need looks like.

    HTH,
    digger

    update
    Forget about Win32::API. I did a little more digging on the Bloomberg API you are working with, and it looks like you are trying to access an ActiveX object, which can only by done thru Win32::OLE.
Re: Accessing Bloomberg API's via Win32::OLE
by unk1911 (Initiate) on Jan 14, 2005 at 18:45 UTC
    Thanks to everyone who replied. These were some good suggestions but I ended up just writing the code in C++ and went directly against the Bloomberg C/C++ API and then just got my C++ program to pass the data back to the Perl program via pipes.