Results 1 to 4 of 4

Thread: How do I connect to a COM interface?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2010
    Posts
    8

    How do I connect to a COM interface?

    I am trying to figure out how to connect to a proprietary piece of hardware in VB 6. It shouldn't be that hard to do through a COM interface and we already have it working with Matlab.

    I'd guess that to connect to the hardware, I'd have to enter a line like:

    Public WithEvents streamer as HRStream.Streamer

    but that doesn't seem to do anything.

    Do I also need to add something to the project in the project menu?

    Here are the directions from the manual:

    ---------------------------------------
    The HRStream.COM interface exposes exactly the same functionality as the ABStreamer .NET library. Thus, any programming language that can deal with COM (Matlab, VB etc) can use HRStream. When HRStream is installed it automatically registers the COM interface on your machine. The interface goes by the name “HRStream.Streamer”. A typical sequence in Matlab could look like this:

    try
    // Create streamer object
    streamer = actxserver( 'HRStream.Streamer' );
    Page 22 of 22
    // Open streamer, connects to the hardware
    streamer.Open();
    // Load a strategy file
    streamer.LoadStrategyFile( … );
    // Compile strategy and set it on the player
    streamer.SetStrategyToPlayer();
    // Play a wave file
    streamer.PlayWav_ua( … );
    // Close the streamer
    streamer.Close();
    // Dispose the streamer
    streamer.delete;
    catch
    // Catch any error and display it
    streamer.Close();
    pause(1);
    streamer.delete;
    error( ['ERROR>> ', lasterr] );
    end
    -----------------------------------------------------

    Any advice would be greatly appreciated.

    Thanks.

  2. #2
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: How do I connect to a COM interface?

    When you say that "it does not work," what does that mean? Is that your only code?

    Did you add a reference to the Com library? If not, Go to Project/References. Click the Browse button, and select the dll that exposes the COM reference. Click OK after you have selected it. If if already appears in the References dialog (it may), then all you need to do is to check the box next to it to add it to your project.

    Create an instance of the object, say:

    Private WithEvents streamer as HRStream.Streamer 'you don't need to make the Public, at least in general

    in you code somewhere,

    streamer.Open 'this is VB, afterall

    Does this generate an error? If not, then proceed. If so... More work is needed




    Dick
    Last edited by DickGrier; May 5th, 2011 at 01:13 PM.
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2010
    Posts
    8

    Re: How do I connect to a COM interface?

    Hey Dick,

    Thanks for the quick response.

    When I say that "it does not work" what I mean is that visual basic gives me the error "User-defined type not defined" when I try to run a program with the line:

    Private WithEvents streamer as HRStream.Streamer



    Quote Originally Posted by DickGrier View Post
    Did you add a reference to the Com library? If not, Go to Project/References. Click the Browse button, and select the dll that exposes the COM reference. Click OK after you have selected it. If if already appears in the References dialog (it may), then all you need to do is to check the box next to it to add it to your project.
    I have not done this and I am quite sure that this is my problem. Unfortunately, I've not been able to figure out which DLL exposes the COM reference. How do I do that?

    David

  4. #4
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: How do I connect to a COM interface?

    Hmm. Browse until you find one that "looks" like it has the right name. Your vendor should have specified the name, so look around for it in the documentation.

    I suspect that the reason that you original code did not work is because it uses late-binding, and the dll must be registered using regsvr32.exe. If you use early binding and specify the reference in the Project/References, VB should take care of registering it when you click "OK." In any case, you have to locate the dll by name, no matter early or late-binding.

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width