• پایان فعالیت بخشهای انجمن: امکان ایجاد موضوع یا نوشته جدید برای عموم کاربران غیرفعال شده است

آموزش ويژوال سي -- كاربردي

saalek110

Registered User
تاریخ عضویت
10 آپریل 2007
نوشته‌ها
212
لایک‌ها
1

msdn:

Where is WinMain in the Starter Code?

The WinMain function is supplied by the class library and is called when the application starts up. Class CWinApp encapsulates the initialization, running, and termination of an application for Windows.

سئوال:
در شروع برنامه چرا winmain نداريم؟
س: البته منظور برنامه هاي mfc است. Win32 ها دارند.
جواب: تابع winmain بوسيله كلاسهاي كتابخانه اي تامين مي شود و موقع شروع اجراي برنامه فراخواني مي شود. كلاس CwinApp شامل اينيتيالايز و اجرا كننده و خاتمه دهنده برنامه ها در ويندوز است.
 

saalek110

Registered User
تاریخ عضویت
10 آپریل 2007
نوشته‌ها
212
لایک‌ها
1

Msdn:
DECLARE_MESSAGE_MAP

Declares that a message map will be used in a class to map messages to functions (must be used in the class declaration).

BEGIN_MESSAGE_MAP

Begins the definition of a message map (must be used in the class implementation).

END_MESSAGE_MAP

Ends the definition of a message map (must be used in the class implementation).

منظور من از اين پست ، نشان دادن جايگاه مسيج مپ بود. كه با رنگ آبي مشخص كرده ام.

توضيح اينكه مسيج مپ ماكرو است.
 

saalek110

Registered User
تاریخ عضویت
10 آپریل 2007
نوشته‌ها
212
لایک‌ها
1
منبع:
http://www.programmers-corner.com/tutorial/4

ساخت یک dll با ویژوال سی 6 برای استفاده در ویژوال بیسیک 6

ابتدا از منوی فایل گزینه new را بزنید و بعد در پنجره باز شده در تب Projects گزینه Win32 Dynamic-Link Library را بزنید. بعد نامی به پروژه بدهید و مکانش را در هارد مشخص کنید.

در پنجره بعدی گزینه An empty DLL project را انتخاب کنید.

---------------------
بعد بایستی فایلی به پروژه بیافزایید.
از منوی فایل باز new را بزنید و بعد در تب Files گزینه C++ Source File را انتخاب و نام SampleCode بدهید.
---------
بعد مراحل بالا را باز برای افزودن فایل دیگری بروید ولی این بار C/C++ Header File را انتخاب کنید. نام فایل را همنام فایل قبلی بدهید.

------
برای اضافه کردن فایل بعدی مراحل قبل را تکرار کنید ولی این بار گزینه text file را انتخاب کنید و نام exports.def را به آن بدهید.

a2.gif

-------------
اضافه کردن کدها:
به فایل SampleCode.h کد زیر را اضافه کنید:
کد:
#include <windows.h>   
int nFirstNum;
int nSecondNum;
به فایل SampleCode.cpp کد زیر را اضافه کنید:
کد:
#include "SampleCode.h"   
   
//This Function will accept a String And two integers   
//It will display the String in a message box, And Return    
//the sum of the two integers   
//This Is intended As a sample of passing info between   
//c++ And visual basic   
   
// Function definition   
int __stdcall MyFunction(char *szString, int nFirstNum, int nSecondNum)   
{   
    //Display a messagebox With the String (just wanted To show you   
    //how To pass a String)   
    MessageBox(NULL,szString,"Sample Code", NULL);   
   
    //Return the sum of the two integers. Notice a VB Long Is an Integer   
    //in c++.    
    return nFirstNum + nSecondNum;   
}
به فایل exports.def کد زیر را اضافه کنید:
کد:
EXPORTS   
    MyFunction    @1
Additional export functions would be @2, @3, ...

--------------------
Build the dll
دکمه F7 را بزنید یا از منوها :
Build > Build SampleProj.dll
بعد این کار در پنجره بیلد باید داشته باشید:
0 errors and 0 warnings
یعنی بی خطا اجرا شود.
حالا در جایی که پروژه را ذخیره کرده اید در پوشه debug فایل dll خود را دارید.
ایجاد نسخه نهایی یا release
از منوی Build گزینه Set Active Configurations را بزنید. پنجره ای باز می شود. Release را انتخاب کنید و ok کنید.
دوباره پروژه را Build کنید.
این بار در مکان ذخیره پروژه یک پوشه جدید به نام Release ایجاد می شود که باز حاوی فایل dll شماست. که قابل استفاده برای ویژوال بیسیک است.

===============================
استفاده در ویژوال بیسیک 6 :
یک پروژه وی بی استاندارد باز کنید.
کد زیر را به پنجره کد بیافزایید:
کد:
Option Explicit   
   
'Declare the c++ dll. In the real world you will probably do this   
'in a module. Note the path to your dll might be different than mine.   
'Also note that the values are being passed ByVal 
Private Declare Function MyFunction Lib _   
    "[COLOR="Red"]c:\pub\sampleproj\debug\SampleProj.dll[/COLOR]" (ByVal szString As String, _   
    ByVal nFirstNum As Long, ByVal nSecondNum As Long) As Long   
       
Private Sub Form_Load()   
    Dim lngResults As Long   
    'call the function. It should display a messagebox with the string   
    'which will originate from the dll, and then another messagebox   
    'from vb with the total of our two longs 
    lngResults = MyFunction("This is a test.", 5, 4)   
    MsgBox "The total is " & CStr(lngResults)   
    Unload Me   
End Sub
آدرس فایل dll (قسمت قرمز) را مطابق مسیر فایل و نام فایل بکنید. (نمی دانم نویسنده اشتباه کرده یا من اشتباه می کنم . مگه نگفت نسخه ریلیز به کار وی بی میاد چرا نسخه دیباگ را استفاده کرده. خودتان تست کنید و حواستان باشد. من که سرسری تست کردم هر دو نسخه در وی بی جواب می داد.)
پروژه وی بی را اجرا کنید.

سالک : من مراحل بالا را انجام دادم مشکلی نبود.
در دلفی 7 هم همین dll که اینجا ساخته شد را استفاده کردم.
برای یادگرفتن طرز استفاده از dll در دلفی به این پست مراجعه کنید:
http://www.parsiforums.com/vb/showpost.php?p=29438&postcount=2
 

saalek110

Registered User
تاریخ عضویت
10 آپریل 2007
نوشته‌ها
212
لایک‌ها
1
از کتاب:
Fast Track Visual C++ 6.0 Programming

یک پروژه دیالوگی بسازید.
فرم را بیاورید.
روی آن داخل یک لیبل نوشته:
TODO: Place dialog controls here
اولین کار شما برداشتن این لیبل است. روی آن کلیک کنید تا انتخاب بشه و بعد دکمه دیلت کیبورد را بزنید.

حالا ما آماده ایم که دو ابزار به فرم بیافزاییم . یک باتون و یک ادیت. ماوس را روی ابزارها که نگه دارید اسامی می آید.
اگر جعبه ابزار ناپدید شده بود. از منوی Tools گزینه Customize را بزنید که یک پنجره می آید. در تب Toolbars تیک Controls را بزنید.

کلاس ویزارد را بیاورید و IDC_EDIT1 را انتخاب کنید و Add Variable را بزنید.

c1.gif

یک پنجره باز می شود. نامی با پیشوند m داریم در ادامه اش text بنویسید تا جمعا بشود m_text .

c2.gif

نوع متغیر را CString بگذارید باشد که برای متغیرهای رشته ای است. ok را بزنید. کلاس ویزارد را هم ok کنید.

روی باتون کلیک راست کرده و پراپرتی را بزنید تاا پنجره صفات آن باز شود. در تب جنرال کپشن را بکنید Click Me که نوشته روی دکمه را عوض کردیم با این کار.

حالا با رفتن به کلاس ویزارد و ادد فانکشن همان طور که قبلا یاد گرفته بودید برای رویداد کلیک دکمه کد بنویسید.

کد:
void CHelloDlgDlg::OnButton1()
{
[COLOR="Red"]
	m_text = "Hello from Visual C++";                              
    UpdateData(false); [/COLOR]                                             
}

پروژه حاضره. اجرا کنید.
حالا با کلیک دکمه در ادیت می نویسد:
Hello from Visual C++

Using UpdateData()
Call UpdateData() with a value of FALSE to display the value now in m_text in the text box, and call UpdateData() with a value of TRUE to load m_text with the value now displayed in the text box.

When you show a dialog box (not a dialog-based program like HelloDlg, however) on the screen, you don’t need to use UpdateData(), because that function is called automatically.
من نتوانستم توضیحات را ترجمه کنم. خودتان ترجمه کنید.
 

saalek110

Registered User
تاریخ عضویت
10 آپریل 2007
نوشته‌ها
212
لایک‌ها
1
http://logix4u.net/Programming/vc++/A_Tutorial_on_creating_DLLs_with_VC++.html


What is Static linking and Dynamic linking ?

The libraries can be linked to the executable in two ways . one is static linking and the other is dynamic linking. Static linking is the method used to combine the library routines with the application. When building the program , the linker will search all the libraries for the unresolved functions called in the program and if found, it will copy the corresponding object code from the library and append it to the executable. The linker will keep searching until there are no more unresolved function references. This is the most common method for linking libraries.This method boasts of ease of implementation and speed but will generate bulky executable. In dynamic linking , the required functions are compiled and stored in a library with extension .DLL. Unlike static linking, no object code is copied in to the executable from the libraries.Instead of that, the executable will keep the name of the DLL in which the required function resides. and when the executable is running , it will load the DLL and call the required functions from it. This method yields an executable with small footprint , but have to compromise on speed a little.

 

saalek110

Registered User
تاریخ عضویت
10 آپریل 2007
نوشته‌ها
212
لایک‌ها
1
از کتاب:
Learn the MFC C++ Classes

An MFC application built on Win3.1x can be run on Win3.1x, Win95, and NT.
An MFC application built on Win95 or NT can be run on either Win95 or NT,
but not on Win3.1x unless it can be recompiled on Win3.1x.
 
بالا