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

21 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. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. توفر شركة الياسمينة في ذلك المجال

    أولا :_ الكثير من المنظفات الممتازة الفاعلية وذات رائحة ذكية في ذات الوقت.

    كما أنها توفر أحدث الأدوات المستخدمة في عملية التنظيف وإزالة البقع الصعبة.

    ثانيا:_ توفر خدمة تنظيف الزجاج وجلي البلاط من المجالس والكنب والموكيت وخلافة.

    ثالثا:_ كما توفر الشركة الكثير والعديد من طرق مكافحة الحشرات والمتابعة المستمرة لمنع ظهور الحشرات مرة أخرى.

    رابعا:_ توفر مجموعة من المبيدات الحشرية ألأمنه علي الصحة والمصرح بها من وزارة الصحة.

    شركة الياسمينه لخدمات التنظيف ومكافحة الحشرات
    شركة تنظيف بجدة
    شركة تنظيف بالبخار بجدة
    شركة تنظيف فلل بجدة
    شركة تنظيف منازل بجدة
    شركة تنظيف شقق بجدة
    شركة نظافة بجدة

    ReplyDelete

leave me messege