[問題] 呼叫CreateFileMapping()名字卻多了W
開發平台(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
→
07/11 17:24, , 1F
07/11 17:24, 1F
→
07/11 17:25, , 2F
07/11 17:25, 2F
→
07/11 17:26, , 3F
07/11 17:26, 3F
→
07/11 17:26, , 4F
07/11 17:26, 4F
→
07/11 17:29, , 5F
07/11 17:29, 5F
推
07/11 18:08, , 6F
07/11 18:08, 6F
→
07/11 18:18, , 7F
07/11 18:18, 7F
→
07/11 18:43, , 8F
07/11 18:43, 8F
推
07/11 22:37, , 9F
07/11 22:37, 9F
→
07/11 22:38, , 10F
07/11 22:38, 10F
→
07/11 22:48, , 11F
07/11 22:48, 11F
→
07/15 09:53, , 12F
07/15 09:53, 12F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章