- Dec 27 Mon 2010 00:00
-
C語言 群組化
- Dec 19 Sun 2010 00:13
-
Android 強制關閉程式 程式碼 [JAVA]
系統流程 onPause() -> onStop() -> onDestroy()
以下是我試過最和平 不會產生錯誤訊息的方法
@Override
protected void onPause() //按下退出鍵 系統預設呼叫 onPause
{
finish();
super.onDestroy(); //這行以防系統以為我亂呼叫
}
@Override
protected void onStop()
{
super.onStop();
super.onDestroy();
finish();
}
@Override
protected void onDestroy(){ //真正作用區
super.onDestroy();
//Kill myself
android.os.Process.killProcess(android.os.Process.myPid());
}
- Dec 17 Fri 2010 00:00
-
C / C++ I/O 開讀檔 處理結構體 Structure
int 共有幾個元素;
int saveFile(){
move_phase=0;
picked=-1;
FILE *f1;
f1 = fopen ("save", "wb");
int i;
fprintf(f1,"%d ",共有幾個元素);
printf("[[%d ]]",共有幾個元素);
for(i=0;i<共有幾個元素;i++){
int j=0;
fwrite(poly,sizeof(struct POLYGONS),共有幾個元素,f1);
}
fclose (f1);
}
int readFile(){
move_phase=0;
picked=-1;
FILE *fPtr;
fPtr = fopen("save", "rb");
if (!fPtr) {
printf("檔案開啟失敗...\n");
return 0;
}
int status,i=0;
fscanf(fPtr,"%d ",&共有幾個元素);
status=fread(poly,sizeof(struct POLYGONS),共有幾個元素,fPtr);
printf("FETCHED %d POLYGONS@",status);
display();
fclose(fPtr);
return 0;
}
- Dec 08 Wed 2010 22:33
-
在VS 2008 底下 創建DLL檔的方式
新建專案 -> Console Application -> 選 DLL File
1. 在 DLL 檔裡面要先 Define 這行!
#define DLL extern "C" __declspec(dllexport)
2. 開始在 DLL 檔裡面寫 Function !!
DLL int sum(int c){ return ++c; }
--------------------------------------DLL 檔寫完了
如何呼叫 DLL 檔裡面的 Function ?
在一個MFC程式中..
HINSTANCE hinstDLL=LoadLibrary(L"theDLL.dll"); //讀取 DLL
if(hinstDLL!=0){ //如果有找到 DLL 檔
typedef int(__cdecl *Connect)(int i); //先宣告一下要連結的函式的prototype
Connect Proc; //宣告一下連結用的Connect指標 (應該是指標吧!?)
Proc = (Connect)GetProcAddress(hinstDLL,"sum"); //用Proc連結 DLL 中的函式
int get=Proc(2); //開始使用DLL中的函式,注意DLL中的函式名稱從sum變成Proc了
FreeLibrary(hinstDLL); //DLL用完沒有利用價值了,就可以扔了
CString g;
g.Format((CString)"%d",get); //這三行是顯示函式回傳的值,應該是2+1=3 才對
MessageBox(g);
}
else{ printf("找不到你的DLL檔啦!你放在哪裡!?"); }
- Dec 06 Mon 2010 22:16
-
C 分割字串
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char str[] = "This is a good example"; //要被分割的
char *s = strtok(str, " "); //分割的判斷字元
char *put[100]; //分割後放入新的字串陣列
int s_count=0; //分幾個了
while(s != NULL) {
put[s_count++]=s; //把分出來的丟進去 結果陣列
s = strtok(NULL, " "); //我不知道 這行幹嘛
}
for(int x=0;x<s_count;x++) //驗收成果
printf("%d %s\n",x,put[x]);
system("pause");
return 0;
}
/*補充 其實改成 strtok(str," @"); 這樣的話
即使是 This@is a good@example
也會分成 "This" "is" "a" "good" "example" 了*/
1


