It is currently Mon Dec 17, 2018 10:52 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: dll through QTMessaging, Developer swears its C/CPP
PostPosted: Tue Nov 06, 2018 10:47 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Jun 23, 2010 5:13 pm
Posts: 180
Hi,
I have been reposting same problem years as there are almost thousands of views but zero replies.
I am far from Class, Methods and OOP way that is why I noway understand the algorithm of source.

from header file:

Command.h:

Code:
#define INITDONE_EVENT      4
#define STATECHANGED_EVENT   5


typedef enum L_ERROR
{
   L_NO_ERROR = 0, /*!< No errors */
   L_CONNECT_ERROR = 1, /*!< The Error of connection */
   L_MEMORY_ERROR = 2, /*!< Out of memory */
   L_RESOURCES_ERROR = 3, /*!< The Error of the allocating resource IPC */
   L_EXIT_ERROR = 7, /*!< The thread terminated */
   L_ARG_ERROR = 10, /*!< Wrong function arguments. */
} L_ERROR;

typedef enum L_COMMAND
{
   L_CMD_NOP = 0, /*!< empty command */
   L_CMD_EXIT = 1, /*!< terminate the thread */
   L_CMD_STOP = 2, /*!< stop the mode of waiting for command */
   L_CMD_START = 6, /*!< start the mode of waiting for command  */

} L_COMMAND;


typedef struct L_HANDLE
{
  L_COMMAND command;
  void* visual_ptr;
  QMutex* image_lock;
}L_HANDLE;

/*Get command to Client thread*/
L_COMMAND getCommand(L_HNDL handle)

/*Send command to the client library thread.*/
void sendCommand(L_HNDL handle, L_COMMAND command );


typedef struct LClient
{
      L_HNDL Client;
      L_COMMAND (*GetCommand)( L_HNDL Cl );
} LSClient;

__declspec(dllexport) L_ERROR LInit( LClient *cl, L_DEV dev, int num );

__declspec(dllexport) L_ERROR LStart( LClient *cl );

__declspec(dllexport) void LShutDown( LClient* cl );




Command.cpp:
Code:
L_COMMAND getCommand( L_HNDL handle )
{
   L_HANDLE* hndl = (L_HANDLE*) handle;
   L_COMMAND cmd;

   cmd = hndl->command;
   hndl->command = L_CMD_NOP;

   return cmd;
}

void sendCommand( L_HNDL handle, L_COMMAND command )
{
   L_HANDLE* hndl = (L_HANDLE*) handle;

   while( hndl->command != L_CMD_NOP )
   {
#ifdef _WIN32
      SleepEx( 10, TRUE );
#else
      usleep( 10000 );
#endif
   }

   hndl->command = command;
}

void initDone( L_HNDL handle )
{
   L_HANDLE* hndl = (L_HANDLE*) handle;
   QCustomEvent* event = new QCustomEvent( (QEvent::Type) (QEvent::User + INITDONE_EVENT) );

   QApplication::postEvent( (QObject*) hndl->visual_ptr, event );
}



MainForm.cpp:
Code:
/* Send start command to lclient */
void mainForm::startSlot()
{
   sendCommand( &l_handle, L_CMD_START );
}

/* Send stop  command to lclient */
void mainForm::stopSlot()
{
   sendCommand( &l_handle, L_CMD_STOP );
}




This is unusual way for me and I can not understand to translate to PB and no hint in the forum.

Will be very glad for any explanation


Top
 Profile  
Reply with quote  
 Post subject: Re: dll through QTMessaging, Developer swears its C/CPP
PostPosted: Wed Nov 07, 2018 12:07 am 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2760
Location: Boston, MA
What is the question?
I see simple C struct's and enumerations and prototypes defined.
I do not see?
Code:
#if defined(__cplusplus) || defined(__cplusplus__)
extern "C" {
#endif
...
...
#if defined(__cplusplus) || defined(__cplusplus__)
}
#endif
So, not sure it is compiled as straight C dll? Use dependency walker to open the dll and confirm the functions are not mangled.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: dll through QTMessaging, Developer swears its C/CPP
PostPosted: Wed Nov 07, 2018 7:05 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Jun 23, 2010 5:13 pm
Posts: 180
Here You Are IfDefs

Code:
#if defined(__WIN32__) || defined(WIN32)

#ifdef LCLIENT_EXPORTS
#define LCLIENT_API __declspec(dllexport)
#else
#define LCLIENT_API __declspec(dllimport)
#endif
#include <windows.h>
#else
#define LCLIENT_API
#endif

#ifdef __cplusplus
extern "C"
{
#endif

#if defined(_MSC_VER)
#pragma warning( disable : 4103 )
#endif

#if defined(__BORLANDC__)
#pragma warning(push)
#if (__BORLANDC__  > 0x0520)
#pragma warn -8059
#else
#pragma warn -pck
#endif
#endif

#if defined (__IBMCPP__)
#pragma pack(1)
#endif

#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__GNUC__)
#pragma pack(push,1)
#define PACKED_1
#endif



and Footer Parts:

Code:
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__IBMCPP__) || defined(__GNUC__)
#pragma pack(pop)
#endif

#ifdef __cplusplus
}
#endif

#endif



Top
 Profile  
Reply with quote  
 Post subject: Re: dll through QTMessaging, Developer swears its C/CPP
PostPosted: Wed Nov 07, 2018 8:02 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Jun 23, 2010 5:13 pm
Posts: 180
This "command.cpp" and "MainForm.cpp" cannot be understood.

If it helps I'd add some more:


Code:
//---------------------------------------------------------------------------
L_COMMAND L_GetCommand(L_HNDL Cl)
{
   libConnect *Client = static_cast<libConnect *>( Cl );
   return Client->GetCommand();
}


//---------------------------------------------------------------------------
void libConnect::InitDone()
{
   PostMessage( client_wnd_, WM_INITED, 0, 0 );
}

//---------------------------------------------------------------------------
void libConnect::SetCommand(L_COMMAND cmd)
{
   EnterCriticalSection( &cs );
   curr_command_ = cmd;
   LeaveCriticalSection( &cs );
}

//---------------------------------------------------------------------------
L_COMMAND libConnect::GetCommand()
{
   L_COMMAND res = L_CMD_NOP;
   EnterCriticalSection( &cs );
   res = curr_command_;
   curr_command_ = L_CMD_NOP;
   LeaveCriticalSection( &cs );
   return res;
}


//---------------------------------------------------------------------------
LRErr libConnect::start()
{
   SetCommand( L_CMD_START );
   return LR_NONE;
}

//---------------------------------------------------------------------------
LRErr Start(H_DEV h)
{
   if( h )
   {
      libConnect* r_manager = static_cast<libConnect*>( h );
      return r_manager->start();
   }
   return LR_BAD_HANDLE;
}
//---------------------------------------------------------------------------
LRErr Stop(H_DEV h)
{
   if( h )
   {
      libConnect* r_manager = static_cast<libConnect*>( h );
      return r_manager->stop();
   }
   return LR_BAD_HANDLE;
}



As seen "static_cast" , "CriticalSection", "PostMessage" and from cpp files class calls possible to use in PureBasic?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Fred and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye