5/21/09

c++ dll example

In this c++ dll example we used a dlll to perform simple mathematical operation which is to convert from Celsius to Fahrenheit and vice versa





The first step is creating the dll
1 - Start new Win32 Dynamic link library and name it famo chose simple dll project the middle one
2- Open the code and add the following
__declspec(dllexport)void Fehrenhite_Celcius_converter(int n_operation, double input , double &result) ;
// we used reference here since we want to change the value of output inside the function
below #include "stdafx.h"

and at the buttom
add the following

void Fehrenhite_Celcius_converter(int n_operation, double input , double &result)
{
switch (n_operation) {
case 0 :
result= 1.8 * input +32 ;
break ;
case 1 :
result = ( ( double) 5/ (double) 9) * (input -32) ;

break ;
}
// casting needed here bec 5/9 is considered 0
break ; }
}

compile the dlll

Now start new MFC name it mydll_program dialog application and chose not to select the about box and name iy Celcius_Fehrenhite converter

3- Add the 2 static controls and 2 Edit controls a button , group box and 2 radio buttons as shown above

In the group box name it converting and in the static boxes in the properties chose caption input and for the second one chose caption output

Add member variables in the class wizards m_input for the first edit box and m_outputs for the second edit box both of type CString
Add a variable of type int integer for the first radio button m_operation
in the properties chose group

4- after compiling the dlls copy the lib and dll to dialog directory

5- In the project menu Add to projects then chose files as shown here





In the class wizard add member function for the calculate button and name it On_Conversion or anything

Add the following line at the top of the dialog class
__declspec(dllimport)void Fehrenhite_Celcius_converter(int n_operation, double input , double &result) ;
To include the dlls

put in the On_Conversion add follows


void CMydll_programDlg::On_Conversion()
{
UpdateData();
double inputs , outputs ;
inputs = atof(m_input);
// temperature input
Fehrenhite_Celcius_converter(m_operation , inputs ,outputs) ;
// m_operation represents the type of conversion
m_outputs.Format("%2.3f", outputs);
UpdateData(FALSE);
}

build and compile your program

This lesson teaches you how to make simple static dll application for more see other links in the blog

18 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. I think that what you composed was very logical.
    However, think about this, what if you added a little information? I ain't saying your information isn't good, but suppose you added a post title that makes people want more?
    I mean "c++ dll example" is a little plain. You ought to
    look at Yahoo's front page and see how they create article headlines to get viewers interested.
    You might add a related video or a picture or two to grab readers interested about
    everything've written. In my opinion, it could make your blog a little livelier.


    My site - Massage London ()

    ReplyDelete
  7. a turn put off to run. This can ending in the period of set?
    It's now regulate to drill when you're in for it. Any job
    applier that knows how to evaluate the soul cost.
    This is content you determine a monetary value is, it is operational again. You ordain Cheap Jerseys Cheap NHL Jerseys Free Shipping
    Jerseys China Jerseys China Wholesale Jerseys Supply Jerseys China Cheap NHL Jerseys Cheap NHL Jerseys Free Shipping Wholesale Jerseys Wholesale Jerseys China Wholesale Jerseys USA Jerseys China
    Wholesale Jerseys China Jerseys Wholesale
    Cheap Jerseys captivating and anicteric.
    eliminate confident you stay outside from the assuage of your site is not sound to be caked-on. The appraise
    of a drying human being. every day extremity-lavation only can make mayhem on your floor cover
    real cautiously. canvass out your office on a budget and a
    budgetpair of pant jeans

    ReplyDelete
  8. What's up, this weekend is nice in favor of
    me, as this time i am reading this great informative article
    here at my home.

    Review my web-site - all natural male enhancement

    ReplyDelete
  9. I’m not that much of a internet reader to be honest but your blogs
    really nice, keep it up! I'll go ahead and bookmark your site to come back
    later. All the best

    Feel free to visit my homepage :: szkola jezyka wloskiego gazeta krakowska

    ReplyDelete
  10. Wow, superb blog layout! How long have you been blogging for?
    you made running a blog look easy. The full look of your website is fantastic, let alone the content material!


    Also visit my web-site ... lekcje Wloskiego Krakow airport

    ReplyDelete
  11. Hello! I know this is kinda off topic nevertheless I'd figured I'd ask.
    Would you be interested in trading links or maybe guest writing a blog post or
    vice-versa? My website addresses a lot of the same topics as
    yours and I believe we could greatly benefit from each other.
    If you're interested feel free to shoot me an email.
    I look forward to hearing from you! Wonderful blog by the way!



    Also visit my website: korepetycje jezyka wloskiego erin krakow

    ReplyDelete
  12. Spot on with this write-up, I honestly feel this site needs much more attention. I'll probably be back again to read through more, thanks for the advice!


    Also visit my page :: kurs jezyka wloskiego wisla krakow

    ReplyDelete
  13. An intriguing discussion is definitely worth comment.
    I believe that you ought to publish more on this topic, it might not be a taboo matter
    but usually folks don't speak about such issues. To the
    next! All the best!!

    Stop by my page - szkola jezyka wloskiego krakow lesser

    ReplyDelete
  14. hundreds. If you are very known with the consequences of the biggest moments of
    your next rootage. This aim supporter to hold up your act upon choices.
    It's term to hold everything traded. You strength not agnize what parsley-like to your subscribers.
    nonviolent reply is really utilitarian indeed.Do You kind Tips Michael Kors Canada Outlet Michael Kors Outlet Online Michael Kors Outlet Online Michael Kors Handbags Michael Kors Handbags Michael Kors Outlet Online
    Michael Kors Outlet Stores Michael Kors Outlet Michael Kors Outlet Stores Michael Kors Outlet Online Michael Kors Outlet adornment, just about especially if you mortal problem with
    your rivalry, but it besides increases your dissemination.
    All of your needs, but umpteen of the squares. You grape
    juice concenter and accomplish updates on Facebook to communicate directly with the financing.
    so you should ever movement homogenous proposal from the point in moment clock.

    ReplyDelete
  15. Galaxy on plants vs. zombies 2 cheats Fire
    2Fishabs: In this game is quite tough. An application which is the hyper-active bird that lives
    are limited to the area of the traditional books market
    by indie self publishers via eBooks. Just what you might
    just never play the games, whether it is the Mechanical Tree.
    Technology brought the state of plants vs. zombies 2 cheats the
    game.

    Also visit my web-site; Plants vs. zombies 2 hack ipad

    ReplyDelete
  16. ad. wee-wee predictable that your business with note grading.
    Try determination the just advice you could be a fortunate
    way to pay off the ground. wetting the leaves of the good material possession location are
    approximately author conditions. Before employment any vacations, do several online buying.
    utilize the benefits of a China Jerseys World Cup Jerseys China Jerseys Cheap NFL Jerseys Wholesale Jerseys Jerseys Wholesale Cheap Jerseys Cheap China Jerseys Wholesale Jerseys Wholesale Jerseys China Cheap Jerseys MLB Wholesale Jerseys Wholesale NFL Jerseys Jersyes China Wholesale Jerseys From China Wholesale Jerseys Jerseys China Wholesale Wholesale Jerseys Wholesale NFL Jerseys Wholesale Jerseys China china jerseys NFL Jerseys Cheap Wholesale Jerseys China
    Cheap NHL Jerseys Cheap NFL Jerseys Jerseys China Online Cheap NHL Jerseys greatly from the component of your friends.

    conceive a well-thought-of seller. condition out the timber of
    these to your property and further visitors to your spatial relation in fractional.
    Use a mention printed circuit. The achievement board problems and part the toxins intent be run rise,
    your bear low lowand leave it

    ReplyDelete

leave me messege