Solved

Serial Port DLL C++

Posted on 2010-08-13
5
818 Views
Last Modified: 2013-12-14
I'm looking to create a C/C++ dll for customers to use to connect to my company's hardware. I have no issue with the communication portion, I looking for a little guidance on how to construct the dll so that when the client programmer links to the dll, it creates an object that is created on linking, exposed methods like add and subtract that are public and available while the dll is linked. Once the WEP is called, the connection is closed and the object is destroyed.

Any and all suggestions are welcome. Thanks!

0
Comment
Question by:PmiDeveloper
5 Comments
 
LVL 9

Expert Comment

by:masheik
ID: 33435318
What is your IDE and compiler?
0
 
LVL 11

Accepted Solution

by:
cup earned 250 total points
ID: 33435574
Constructing the DLL

File/New/Project

New Project
=========
On the left, Select Visual C++ Projects
On the right, Select Win32 Console Project
Type in the project name etc
Click OK

Win32 Application Wizard
==================
click Application Settings

Win32 Application Wizard
==================
Select DLL
Select Export Symbols
Click Finish

What you'll get is an example header and source which exports symbols for  
   o  a class
   o  a variable
   o  a function.

And that's it.  The rest of the stuff like precompiled headers and code generation types you probably already know.

Not sure if you're having problems with the design of the behavioural bits of your DLL
0
 

Author Comment

by:PmiDeveloper
ID: 33436178
@masheik - I'm currently have copies of Dev-C++, and Visual C++ Express 2010. Dev-C++ doesn't seem to have any easy way to export the symbols and I'm not sure on the limitation of the express version yet.

@cup - I did some more research after I posted the question and I think I found part of my answer. I believe I can use the states within the DLL main function to initialize a connection and state of an object on linking, and close a connection and destroy an object on release. Does that sound correct?
0
 
LVL 11

Expert Comment

by:cup
ID: 33438025
On MS, DLLs are actually executables where main is called DLLMain.  DLLMain is just an entry point to keep the linker happy.  When it was Windows 2.x and 3.x, it was used but I've never seen it in use on either NT or anything that came after 95.

There is nothing to stop you from doing it the way you suggested but I don't know whether it will work or not.  Also, how are you using the DLL?  Are you using LoadLibrary or are you linking it in?  If you're using LoadLibrary, you're in charge of what gets called and what doesn't.  If you're linking it in, you need to call some routine to create the connection and to destroy.  That can be done in several ways, depending on how you design your code.
0
 
LVL 3

Assisted Solution

by:xpero
xpero earned 250 total points
ID: 33453520
Hi,
in most IDEs there a template project for creating dlls : file->new ->project->Dynamic link library.

You can use dll entry point call reasons to creat and destroy the connection state.


BOOL WINAPI DllMain(

    HINSTANCE hinstDLL,  // handle to DLL module

    DWORD fdwReason,     // reason for calling function

    LPVOID lpReserved )  // reserved

{

    // Perform actions based on the reason for calling.

    switch( fdwReason ) 

    { 

        case DLL_PROCESS_ATTACH:

         // Initialize once for each new process.

         // Return FALSE to fail DLL load.

            break;



        case DLL_THREAD_ATTACH:

         // Do thread-specific initialization.

            break;



        case DLL_THREAD_DETACH:

         // Do thread-specific cleanup.

            break;



        case DLL_PROCESS_DETACH:

         // Perform any necessary cleanup.

            break;

    }

    return TRUE;  // Successful DLL_PROCESS_ATTACH.

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio Debugging 3 121
Best free Visio Editor? 2 136
How to install SVN Command Line Client? 5 39
Support for Notepad++ (including downloading & installing a plugin) 5 59
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now