作者jeep168917 (幫幫)
看板C_and_CPP
標題[問題] CreateFileMapping
時間Thu Jul 11 17:15:35 2013
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
不太清楚為什麼會出現CreateFileMappingW,錯誤特別是還多了"W"
error2和3也很奇怪,不知道是哪裡出了問題
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
Error1 error C2664: 'CreateFileMappingW' : cannot convert parameter 6 from
'char [14]' to 'LPCWSTR'
Error2 error C2146: syntax error : missing ')' before identifier '_DATE_'
Error3 error C2059: syntax error : ')'
程式碼(Code):(請善用置底文網頁, 記得排版)
// 23d.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "23d.h"
#include "stdlib.h"
#include "windows.h"
#include "stdio.h"
#define SHAREMEM_NAME "c:shareMemory"
#define BULID_MESSAGE "Today is"_DATE_" "_TIME_
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
///
LPCTSTR pBuf;
HANDLE hFile;
int i;
char szFileName[]=SHAREMEM_NAME;
char writeBuffer[128]={0};
//宣告變數
//建立共用記憶體
hFile=CreateFileMapping(
(HANDLE)0xFFFFFFFF,
//表示內存中開闢一個區塊
NULL,
PAGE_READWRITE,
//讀取在一個區塊
0,
sizeof(writeBuffer),
//代表一個內存中的二進制數據區塊正在累計讀入
szFileName
);
//建立一個大小為1024bytes的分享記憶體
//得到映射(位址)的記憶體
pBuf=(LPCTSTR)MapViewOfFile(
hFile,
FILE_MAP_ALL_ACCESS,
0,
0,
sizeof(writeBuffer)
);
//放入自己的位址空間
//創造新的連結並顯示
strcat((char*)pBuf,BULID_MESSAGE "\n");
while(1){
printf("%s\n",pBuf);
Sleep(1000);
}
CloseHandle(hFile);
}
補充說明(Supplement):
最近正在研究shared memory,我是新手,若有違反版規,我願意刪文,感恩!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.99.166.2
→ azureblaze:專案設定->character set->Multi-byte 07/11 17:24
→ azureblaze:winapi很多都分成char/wchar_t兩種 07/11 17:25
→ azureblaze:xxxx -> xxxxA / xxxxW 07/11 17:26
→ azureblaze:專案設定可以選擇預設要呼叫那一種 07/11 17:26
→ jeep168917:請問我是英文版,是在Property裡面嗎? 07/11 17:29
推 damody:一樓推文不是寫英文嗎? 07/11 18:08
→ purincess:"專案設定"不是英文 XDDDDDD 07/11 18:18
→ azureblaze:properties->general 07/11 18:43
推 ThomasHuang:這是寬字元字集與單字元字集的問題 07/11 22:37
→ ThomasHuang:把字串改成這樣 _T("我是字串") 07/11 22:38
→ fakeqq:date & time 前後各為2個底線 07/11 22:48
→ jeep168917:更改完,跑出更多的error @@ 07/15 09:53