This page looks plain and unstyled because you're using a non-standard compliant browser. To see it in its best form, please upgrade to a browser that supports web standards. It's free and painless.

This site is about Game Programming.
相簿 | 部落格 | 留言 | 名片 | 管理介面
pinglunliao | 15 June,2008 13:47

透空效果:
原圖
     // 背景圖
     SelectObject(mdc, bg);
     BitBlt(hdc, 0 ,0 , 600, 450, mdc, 0, 0, SRCCOPY);
 
     // 透空圖
     SelectObject(mdc, dra);
     BitBlt(hdc, 280, 320, 85, 99, mdc, 85, 0, SRCAND);
     BitBlt(hdc, 280, 320, 85, 99, mdc, 0, 0, SRCPAINT);
結果
(繼續閱讀...)

pinglunliao | 16 March,2008 14:42

緣由有兩點:
1.          寒假時上C++教學DLL的部份有同學問我此問題。
2.          最近和 remmurds在討論這兩套IDE產生出來的DLL如何共用。

 
Using BCB6 to create a DLL Project
FileèNewèOther,選DLL Wizard
Wizard Option 要記得勾 VC++ Style DLL
 
 
  
分別建立 Header File Source File如下:
 
//DLLTest.h
#ifndef DLLTEST_H
#define DLLTEST_H
 
extern "C" __declspec(dllexport) long Count(int n, int m);
 
#endif
 
//DLLTest.cpp
#include <windows.h>
#include "DLLTest.h"
 
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
        return 1;
}
 
extern "C" __declspec(dllexport) long Count(int n, int m)
{
        return n + m;
}
 
檔案編輯好後,從主選單的ProjectBuild Project,在專案的資料夾會產生一個DLL檔,此檔會在[Using VC++ 2005 to build a DLL Demo Project]用到。
 
 
 
Using VC++ 2005 to build a DLL Demo Project
FileèNewèAdd a New Project,選擇空專案
將在[Using BCB6 to create a DLL Project]中所建立的 Header File加到專案裡,並建立一測試用的Source FileCode如下:
 
#include <iostream>
#include <windows.h>
#include "DLLTest.h"
 
typedef long (__cdecl *CountProc)(int, int);
 
int main(void)
{
     long (*Count)(int, int);
     HINSTANCE hInst = LoadLibrary(L"DLLTest.dll");
 
     Count = (CountProc)GetProcAddress(hInst, "_Count"); // 要加上底線,見觀念講解
 
     long result = Count(5, 5);
     std::cout << result << std::endl;
 
     system("PAUSE");
 
     FreeLibrary(hInst);
     return 0;
 
}
 
產生出來的執行檔需和[Using BCB6 to create a DLL Project]中所Build出來的DLL放在同一資料夾,成功執行的畫面如下:
(繼續閱讀...)

pinglunliao | 26 January,2008 13:05

除了方法一的結果是不如預期,其他四個都是OK

方法一:使用區域陣列
local array
 #include <stdio.h>
 
float *fun(void)
{
    int i;
    float fArray[10];
    for( i = 0; i < 10; i++ )
        fArray[i] = i + i / 2.0f;
   
    return fArray;
}
 
int main(void)
{
    int i;
    float *fPtr;
   
    fPtr = fun();
   
    for( i = 0; i < 10; i++ )
        printf( "%f\t", fPtr[i] );
   
    printf("\n");
    return 0;
}
 
warning: function returns address of local variable
 
方法二:使用靜態陣列 static array
#include <stdio.h>
 
float *fun(void)
{
    int i;
    static float fArray[10];
    for( i = 0; i < 10; i++ )
        fArray[i] = i + i / 2.0f;
   
    return fArray;
}
 
int main(void)
{
    int i;
    float *fPtr;
   
    fPtr = fun();
   
    for( i = 0; i < 10; i++ )
        printf( "%f\t", fPtr[i] );
   
    printf("\n");
    return 0;
}
 
方法三:使用結構
#include <stdio.h>
 
struct fArray
{
    float data[10];
};
 
struct fArray fun(void)
{
    int i;
    struct fArray tempArray;
    for( i = 0; i < 10; i++ )
        tempArray.data[i] = i + i / 2.0f;
   
    return tempArray;
}
 
int main(void)
{
   int i;
    struct fArray data;
   
    data = fun();
       
    for( i = 0; i < 10; i++ )
        printf( "%f\t", data.data[i] );
   
    printf("\n");
    return 0;
}
 
方法四:使用動態記憶體
#include <stdio.h>
#include <stdlib.h>
 
float *fun(void)
{
    int i;
    float *tempArray;
   
    tempArray = malloc(sizeof(float)* 10);
    if( tempArray == NULL )
        exit(1);
   
    for( i = 0; i < 10; i++ )
        tempArray[i] = i + i / 2.0f;
   
    return tempArray;
}
 
int main(void)
{
    int i;
    float *data;
   
    data = fun();
       
    for( i = 0; i < 10; i++ )
        printf( "%f\t", data[i] );
   
    printf("\n");
   
    free(data);
    return 0;
}
 
方法五:使用傳址呼叫
#include <stdio.h>
#include <stdlib.h>
 
void fun(float tempArray[])
{
    int i;
   
    for( i = 0; i < 10; i++ )
        tempArray[i] = i + i / 2.0f;
}
 
int main(void)
{
    int i;
    float data[10];
   
    fun(data);
       
    for( i = 0; i < 10; i++ )
        printf( "%f\t", data[i] );
   
    printf("\n");
   
    free(data);
    return 0;
}
 


pinglunliao | 30 December,2007 13:59

#include <stdio.h>
#include <stdlib.h>

(繼續閱讀...)

pinglunliao | 24 December,2007 20:05


 CDC dcMem;            // memory dc
 
 CRect rect;
 GetClientRect( &rect );
 
(繼續閱讀...)

pinglunliao | 7 December,2007 20:16

作者:金蝶中間件公司CTO袁紅崗 

(繼續閱讀...)

pinglunliao | 18 September,2007 13:57

 // A simple program to demonstrate the GLUT 


(繼續閱讀...)