C++ dll with Mscomm control: Debug assertion failed error

Hi, I need to create a Visual C++ dll to be called by a VB6 program. In the C++ dll, an MSComm control is required for serial communication. However, when my VB6 program calls the below, it will hit a "Debug Assertion failed" error. Pardon me as I am new to c++.
I know this implementation of using VB6-->C++--> MSComm sounds weird but is necessary to avoid changing tonnes of programs.
Please advise, it's urgent.





// VCDLLA.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "VCDLLA.h"
#include "mscomm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


BEGIN_MESSAGE_MAP(CVCDLLAApp, CWinApp)
      
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVCDLLAApp construction

CVCDLLAApp::CVCDLLAApp()
{
      // TODO: add construction code here,
      // Place all significant initialization in InitInstance

}


/////////////////////////////////////////////////////////////////////////////
// The one and only CVCDLLAApp object

CVCDLLAApp theApp;


_declspec(dllexport) int ReportVersion() {
      AFX_MANAGE_STATE(AfxGetStaticModuleState());
      CMSComm m_comm;
      m_comm.SetCommPort(1);
      m_comm.GetCommPort();
      m_comm.SetCommPort(1);
      m_comm.SetSettings("9600,o,8,1");
      m_comm.SetInputLen(1);
      m_comm.SetInputMode(0);
      m_comm.SetRTSEnable(TRUE);
      m_comm.SetRThreshold(1);
      m_comm.SetSThreshold (1);
      m_comm.SetPortOpen(true);
      m_comm.SetOutput(COleVariant("Hello456"));
    return 13;
}
shiaoyan05Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sakuya_suCommented:
Debug assertion failed error

that is because in your C++ code, there is an Assert command somewhere checking an condition, you will need to look through the code and find where this assert is and see why it is being triggered
0
shiaoyan05Author Commented:
I have looked through the code but did not find any assert command.
Please advise.
I was just wondering if my instantiation of the MSComm object should work this way?
0
sakuya_suCommented:
   m_comm.SetCommPort(1);
      m_comm.GetCommPort();
      m_comm.SetCommPort(1);

why is it like that?

Other than that i see your code is correct in creating a new comm....
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

shiaoyan05Author Commented:
Hi,
It is supposed to be
CMSComm m_comm;
m_comm.SetCommPort(1);
m_comm.SetSettings("9600,o,8,1");

My VB program will then call c++ ReportVersion() method. This is when I will hit the assertion error, at the first line: m_comm.SetCommPort(1);

Thanks
0
sakuya_suCommented:
Had a look:

void AFX_CDECL CWnd::InvokeHelper(DISPID dwDispID, WORD wFlags, VARTYPE vtRet,
      void* pvRet, const BYTE* pbParamInfo, ...)
{
      ASSERT(m_pCtrlSite != NULL);

That is called on the m_comm.SetCommPort(1);

this indicates that you do not have MSComm component registered..

you should either install it from the VC++ CD..... or.. use regsvr32 on it
0
sakuya_suCommented:
to be more specific... you need to regsvr32 mscomm32.ocx

then you need to add reference to it in your C++ project.. which I, unfortunately have no idea how to do as I have not done alot of SDI stuff

maybe someone else here can say more on this.
0
EDDYKTCommented:
Do you have problem to compile your dll in release mode and call from Vb?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EDDYKTCommented:
Also check on this link

http://www.morovia.com/supportforum/forum_posts.asp?TID=53&PN=1
>>Here's a quick example of how to use the control. It's important to wait until your OnInitDialog() call (or anytime after) before trying to use it because not everything will be created/initialized before this
0
shiaoyan05Author Commented:
I manage to run without error when compiled in a Release version. However, nothing is displayed. It is a working code. I also cannot create a dialog as I need it to be built as a dll. Pardon my questions as I am a newbie
0
shiaoyan05Author Commented:
When calling from VB6 i managed to retrieve the commport throught the C++ method:
However, the comm port returned is 19 though I have set it to 1.
Please help

C++ code:
===
 CMSComm m_comm;
      m_comm.SetCommPort(1);
      m_comm.SetSettings("9600,o,8,1");
      m_comm.SetInputLen(1);
      m_comm.SetInputMode(0);
      m_comm.SetRTSEnable(TRUE);
      m_comm.SetRThreshold(1);
      m_comm.SetSThreshold (1);
      m_comm.SetPortOpen(true);
      m_comm.SetOutput(COleVariant("Hello456"));
return m_comm.GetCommPort();
0
EDDYKTCommented:
You may want to move this line to your header file and try. Give it sometime to initialize

CMSComm m_comm;
0
shiaoyan05Author Commented:
Hi,
If I put it at different parts of the codes/ header, it will return a different port number eg. 836 etc.
This code will run properly in exe but hit issues when running dll. can anyone help to provide a sample for using mscomm in dll?
0
sakuya_suCommented:
hmm.... does this dll generate any forms? buttons etc?
0
EDDYKTCommented:
is it possible your com1 already open by something?

what is m_comm.GetPortOpen()
0
shiaoyan05Author Commented:
Hi Thanks to all who have helped so far. I did not manage to get it to work though it compiled correctly..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.