Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Mike Grove

@Mike Grove
About
Posts
9
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Using C# DLL in C++ App - nearly there...
    M Mike Grove

    I realise there is a lot of stuff out there relating to this need, but I'm still struggling...so any pointers to where I'm going wrong are appreciated. I'm attempting to use the ModbusTCP DLL (available elsewhere on these forums) in my C++ console test app (with CLR support enabled) and it compiles ok. However, it crashes even before execution even gets to the first printf(...). Code is as follows, error details are after the code;

    #include "stdafx.h"
    #include "conio.h"

    #using "ModbusTCP.dll" // TCP Master implementation
    using namespace ModbusTCP;

    int _tmain(int argc, _TCHAR* argv[])
    {
    printf( "About to create MBmaster..." );
    try
    {
    // Create new modbus master and add event functions
    Master^ MBmaster = gcnew Master( "192.168.100.1", 23 );
    printf( "MBmaster created ok" );
    }
    catch ( ... )//SystemException error )
    {
    //MessageBox.Show( error.Message );
    printf( "Error caught" );
    }

    while ( !\_getch() )
    	;
    return 0;
    

    }

    Error dialog contains the following text: "An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module. Could not load file or assembly 'ModbusTCP, etc, or one of its dependencies".

    C / C++ / MFC csharp c++ dotnet help

  • Ethernet code for talking to Hardware I/O
    M Mike Grove

    Thanks Richard - I'm particularly interested in that 'Beginner' link... :-D

    C / C++ / MFC c++ hardware

  • Ethernet code for talking to Hardware I/O
    M Mike Grove

    I need to write some code (using C++/VS2010/Windows7), that can talk to a hardware I/O module (PhoenixContact Axioline F Bus Coupler) which is connected via Ethernet and, as usual, have never done this before. I just need someone to point me in the right direction so I can get started, if possible please... There's plenty of stuff on MSDN, eg.

    Quote:

    Getting Started with Winsock

    , but I don't have the confidence to dive right in just yet.

    C / C++ / MFC c++ hardware

  • _com_error not caught by 'Try-Catch' code
    M Mike Grove

    Ooops, sorry - I missed your reply earlier! Yes, you were correct - thank-you :thumbsup: Feeling like a newbie (again) :(

    C / C++ / MFC c++ question csharp visual-studio com

  • _com_error not caught by 'Try-Catch' code
    M Mike Grove

    Ok, got it thanks - Windows was catching the error and not re-throwing it because... I'm running in Debug and had Visual Studio set to catch all Exceptions :-O

    C / C++ / MFC c++ question csharp visual-studio com

  • _com_error not caught by 'Try-Catch' code
    M Mike Grove

    I have added some code (to an existing MFC/ATL application), to communicate with a piece of hardware that comes complete with com-based driver software. (Before I forget: I'm writing C++ in Visual Studio 2010, for Windows7). My code is based closely upon the sample code that the hardware manufacturer supplied, and is as follows;

    #import "GlobMgr.dll" no_namespace // I/O funtionality
    #import "IviDriverTypeLib.dll" no_namespace // IVI inherent functionality
    #import "agu265x.dll" no_namespace // Instrument specific functionality

    IAgilentU265xPtr spAgDrvrSlot1;

    CCMDS::CCMDS( ...class details not relevant... )
    : CUSBDevice( ...ditto... )
    {
    // Must first call either CoInitialize or CoInitializeEx to initialize COM **DON'T NEED THIS BIT - COM ALREADY INITIALISED**
    //HRESULT hr = S_OK;
    //hr = CoInitialize( NULL );
    //if ( hr != S_OK )
    //{
    // if ( hr == S_FALSE )
    // {
    // AfxMessageBox( "Com Already Initialised" );
    // }
    // else
    // {
    // AfxMessageBox( "Co-initialise Failed" );
    // }
    //}

    // Create and Initialise instances of the Agilent driver for
    // each of the four U2635A I/O modules in the U2781A rack
    spAgDrvrSlot1.CreateInstance( __uuidof( AgilentU265x ) );

    try
    {
    spAgDrvrSlot1->Initialize( "USBInstrument1", VARIANT_FALSE, VARIANT_TRUE, "" );
    }
    catch ( _com_error e )
    {
    AfxMessageBox( "Driver Initialise Failed" );
    }

    HOWEVER, my code crashes at the Initialize(USBInstrument1...) statement with a Windows dialog saying

    Quote:

    First-chance exception at 0x755bb9bc in IOHandler.exe: Microsoft C++ exception: _com_error at memory location 0x001de4e0..

    Why this code fails at all is a mystery but the big question is why does Windows crash with a dialog rather than my Try-Catch code catching the error in the controlled fashion I'd hoped for??

    C / C++ / MFC c++ question csharp visual-studio com

  • Serial Port OK in class constructor but not outside...
    M Mike Grove

    Thank-you, David. That wasn't the solution (see Jochen's reply above), but yours was still good advice...

    C / C++ / MFC help database com workspace

  • Serial Port OK in class constructor but not outside...
    M Mike Grove

    Many thanks, Jochen, that was the solution! (I live and learn...).

    C / C++ / MFC help database com workspace

  • Serial Port OK in class constructor but not outside...
    M Mike Grove

    I am opening a COM port in a class constructor - no problem. I can send some data at this point too - no problem. BUT, if I try to send data from any other method in the class it appears to work ok (I get the expected ERROR_IO_PENDING), but subsequently my code suffers an unpredictable and undebuggable crash. Any ideas anyone (please ask for more info' if needed)... Some code;

    CSerialDevice::CSerialDevice(
    CString& strDeviceId,
    CString& strDeviceName,
    CString& COMPort,
    CString& BaudRate,
    CString& Format,
    ComWrapper_c Db, GobList_t& rGobList,
    CSerialIOInterface* pInterface )
    : pOurInterface( pInterface ),
    m_hCommPort( NULL )
    {
    // Create the items for the device
    AddDigitalItems( strDeviceName, strDeviceId, Db, rGobList );
    AddAnalogueItems( strDeviceName, strDeviceId, Db, rGobList );

    // Configure the COM port for the device
    if ( !ConfigureSerialPort( COMPort, BaudRate, Format ) )
    {
    	pOurInterface->AddErrorToStatus( "Failed to configure port for " + strDeviceName );
    }
    

    }

    /////////////////////////////////////////////////////////////////////////////
    //
    //
    //
    /////////////////////////////////////////////////////////////////////////////
    bool CSerialDevice::ConfigureSerialPort(
    CString& strCOMPort,
    CString& strBaudRate,
    CString& strFormat )
    {
    // Open the port
    m_hCommPort = CreateFile(
    strCOMPort,
    GENERIC_READ | GENERIC_WRITE,
    0,
    0,
    OPEN_EXISTING,
    FILE_FLAG_OVERLAPPED,
    0 );

    // Get the default configuration...
    DCB dcb = {0};
    dcb.DCBlength = sizeof(DCB);
    if ( !GetCommState( m\_hCommPort, &dcb ) )
    {
    	return false;
    }
    
    // ...and change the items we want to
    dcb.BaudRate = atoi( strBaudRate );
    dcb.ByteSize = atoi( strFormat.Left( 1 ) );
    int parity = NOPARITY;
    if ( strFormat.Mid( 1 ) == 'N' )
    {
    	parity = NOPARITY;
    }
    else if ( strFormat.Mid( 1 ) == 'E' )
    {
    	parity = EVENPARITY;
    }
    else if ( strFormat.Mid( 1 ) == 'O' )
    {
    	parity = ODDPARITY;
    }
    dcb.Parity = parity;
    int stopBits = atoi( strFormat.Right( 1 ) );
    switch ( stopBits )
    {
    case 0  : stopBits = ONESTOPBIT; break;
    case 2  : stopBits = TWOSTOPBITS; break;
    default : stopBits = ONESTOPBIT; break;
    }
    dcb.StopBits = stopBits;
    if ( !SetCommState( m\_hCommPort, &dcb ) )
    {
    	return false;
    }
    
    COMMTIMEOUTS timeouts;
    timeouts.ReadIntervalTime
    
    C / C++ / MFC help database com workspace
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups