CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Using MSComm control with out a form

  1. #1
    Join Date
    Jul 2002
    Posts
    7

    Using MSComm control with out a form

    I am creating a project that is an activeX Dll, which well contain a set of functions to control a camera, connected to the CommPort. I would like to use MSComm control to provide serial communication, but how do I use the control with out a container control such as the form? I guess I could create a form with the MSComm control on it, but never show the form. Is there a better way?

  2. #2
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    You can achieve that by using a class module and the followind declaration:

    Code:
    Private WithEvents objMSCOMM As MSComm
    
    Private Sub objMSCOMM_OnComm()
    
    End Sub
    You can name your control as you want and will be able to receive the event, make sure you use a class module and not a regular module

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  3. #3
    Join Date
    Jul 2002
    Posts
    7
    Jeff

    The following is the code I tried, but I get a compile error, invalid use of the New keyword, if I remove the Set statement, I get a run-time error when at the statement objMSCOMM.CommPort = 1 is executed. The error is that the object variable is not set.


    Option Explicit
    Private WithEvents objMSCOMM As MSComm

    Public Function PowerCameraOn(
    CameraModelID As Integer, _
    CameraAddress As Integer, _
    CommPortNumber As Integer)


    Set objMSCOMM = new MSComm

    objMSCOMM.CommPort = 1.
    objMSCOMM.Settings = "9600,N,8,1"
    objMSCOMM.InputLen = 0

    objMSCOMM.PortOpen = True

    End Function

  4. #4
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    Hello wintersj,

    MSCOMM does not support such a thing. You're stuck by using a form. A quick search on the net and it seems it is impossible to use a class module with objects that do not support new. So you can't use WithEvents with a timer for example. However, you can still use that with ADODB or with WORD objects. Sorry, I thought it was possible... you really have to do it with a form. To use the less ressource possible, set the form HasDC to false, AutoRedraw to false and as you already surely know: Visible to false and ShowInTaskbar to false

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  5. #5
    Join Date
    Jul 2002
    Posts
    7
    Thanks Jeff, for the help. Jim

  6. #6
    Join Date
    Feb 2008
    Posts
    1

    Re: Using MSComm control with out a form

    I know it's an old thread, but I got into the same problem and I found a way on another forum. Here is the link:
    http://forums.devx.com/showthread.php?t=43724

    In brief, you have to add mscomm32.ocx in your project as a reference instead of component. Then you use it that way:

    Declaration:
    Private myComm As MSCommLib.Comm

    Before you use it, initialization:
    set myComm = NEW MSCommLib.Comm

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)