このサイトを参考にしてcopyfile関数のサンプルを作成しました。
したのPath2とPath3でcopyfile関数を行っても正常に動作しません。
messagebox関数では絶対パスは正しく表示されたのですが、
回答お願いします。
#include <windows.h> #include <stdio.h> #include<tchar.h> #include <shlwapi.h> #pragma comment(lib, "shlwapi.lib") #define MSG(m) {\ MessageBoxA(NULL,m,NULL,MB_OK);} //ウィンドウハンドル HWND hwnd; //インスタンスハンドル HINSTANCE hinst; //ウィンドウ横幅 #define WIDTH 500 #define HEIGHT 300 TCHAR Path[260]; TCHAR Path2[260]; TCHAR Path3[260]; TCHAR copy[260]; TCHAR paste[260]; LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { char buf[1000]; static HANDLE h; switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_LBUTTONDOWN: h = CreateFile("test.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (h != INVALID_HANDLE_VALUE) { MSG("ファイル作成に成功しました"); CloseHandle(h); //ファイルをtest2という名前で同じ階層にコピー if (!CopyFile("test.txt", "test2.txt", FALSE)) { MSG("copyfile関数失敗"); } //ディレクトリ作成 CreateDirectory("temp", NULL); if (!MoveFile("test2.txt", "./temp/test2.txt")) { MSG("movefile関数失敗"); } GetCurrentDirectory(sizeof Path, Path); MSG(Path); _stprintf_s(Path2, sizeof(Path2)/sizeof(Path2[0]), "%s\test.text" ,Path); MSG(Path2) _stprintf_s(Path3, sizeof(Path3) / sizeof(Path3[0]), "%s\tempg",Path); MSG(Path3) if (!CopyFile(Path2, Path3, FALSE)) { MSG("getcurrentdirectoryによるcopyfile関数失敗"); } } return 0; } return DefWindowProc(hwnd, msg, wp, lp); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { MSG msg; WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WinProc; wc.cbClsExtra = wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hCursor = wc.hIcon = NULL; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszClassName = "test"; wc.lpszMenuName = NULL; if (!RegisterClass(&wc)) { MSG("クラスの登録失敗"); return -1; } //インスタンスハンドル hinst = hInstance; hwnd = CreateWindowA("test", "テストウィンドウ", WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 400, 400, NULL, NULL, hInstance, NULL); if (hwnd == NULL) { MSG("ウィンドウ作成失敗"); return -1; } //エラーチェック用変数 int check; while (check = GetMessage(&msg, NULL, 0, 0)) { if (check == -1) { break; } DispatchMessage(&msg); } //クラス解放 UnregisterClass("test", hinst); return 0; }
正常に動作しないとはどうなるんでしょう。
関数が失敗すると言うならlasterrorを取ってきてそれを提示しましょう

回答1件
あなたの回答
tips
プレビュー