特定フォルダのpngファイル名を取得してそれを元に画像をロードするプログラムとして下記の記述1のように記述したところ無事動作しました。
これを受けてこのプログラムのファイルを検索する関数を抜き出し、フォルダのパスと拡張子を指定してファイルを検索してファイル名を取得する関数として下記の記述2のように一部書き換えて別のプログラムに移植したところ、こちらでは21,43,64行目にてビルド時に「'FindFirstFileW' : 1 番目の引数を 'char *' から 'LPCWSTR' に変換できません。」、「'strcpy' : 2 番目の引数を 'WCHAR [260]' から 'const char *' に変換できません。」といったエラーが発生してしまいました。
この二つの間の差異として思いつく点にはインクルードするファイルの違いがありますが、この部分を書き換えてもやはりエラーの状況に影響はありませんでした。
これらの関数の間で変数の形式や構造などは手を加えていないのですが、一体この二つの間にどんな違いがあって記述2がエラーを発生させてしまうのでしょうか?
記述1
#include "DxLib.h"
#include <windows.h>
#include <tchar.h>
#include <math.h>
#define MAXPATH 256
char **SearchFile(char *FolderPass,char *ExtPass,int *FileAmount){
int i,j;
//ファイル検索用
WIN32_FIND_DATA fFind;
HANDLE hSearch;
char *FindPath; //検索用パス(フォルダパス+拡張子)
//画像名格納用
char **FileName; //ファイル名一覧格納ポインタ
char **FileName2; //ポインタサイズ変更用ポインタ
int FileNameLong=0; //ファイル名文字数
//ファイル検索
FindPath=(char*)malloc(sizeof(char*)*(strlen(FolderPass)+strlen(ExtPass)));
strcpy(FindPath,FolderPass);
strcat(FindPath,ExtPass);
hSearch=FindFirstFile(FindPath,&fFind); // 探索開始
//1個目が見つからない場合
if (hSearch==INVALID_HANDLE_VALUE) {// 見つからなければ探索終了
FindClose(hSearch);
return 0;
}
else{
i=1;
j=0;
while(fFind.cFileName[j]!='\0'){
j++;
}
FileNameLong=j;
FileName2=(char**)malloc(sizeof(char*)*i);
for(j=0;j<i;j++){
FileName2[j]=(char*)malloc(sizeof(char*)*FileNameLong);
}
FileName=FileName2;
FileName2=NULL;
strcpy(FileName[i-1],fFind.cFileName);
//残りを検索
while (FindNextFile(hSearch,&fFind)) { /* 全ファイルを処理 */
i++;
j=0;
while(fFind.cFileName[j]!='\0'){
j++;
}
FileNameLong=j;
FileName2=(char**)malloc(sizeof(char*)*i);
for(j=0;j<i;j++){
FileName2[j]=(char*)malloc(sizeof(char*)*FileNameLong);
}
for(j=0;j<i-1;j++){
strcpy(FileName2[j],FileName[j]);
}
FileName=FileName2;
FileName2=NULL;
strcpy(FileName[i-1],fFind.cFileName);
}
*FileAmount=i;
}
FindClose(hSearch);
return FileName;
}
void hoge()
{
//フォルダ絶対パス検索用
int i,j;
int length; //プロジェクト実行ファイルパスサイズ
char *X; //[\]から[/]へ書き換え用
char delpath[] = "Debug\\DXlib_test.exe"; //消す文字列(サイズ測定用)
char picfol[] = "Data\\Pics\\TileA\\"; //目的フォルダ相対パス
char path[MAXPATH]={0}; //プロジェクトフォルダパス格納用
char *picpath; //picフォルダ絶対パス格納用
//ファイル検索用
WIN32_FIND_DATA fFind;
HANDLE hSearch;
char *FindPath; //検索用パス(フォルダパス+拡張子)
char FindPng[] = "*.png"; //pngファイル検索用
//画像名格納用
char **FileName; //ファイル名一覧格納ポインタ
char **FileName2; //ポインタサイズ変更用ポインタ
int FileNameLong=0; //ファイル名文字数
int FileAmount; //検索したファイルの数
//画像ハンドル格納用
char *LoadPath;
int *hpicture;
//picフォルダパス検出
length = GetModuleFileName(NULL, path, MAXPATH);
path[length-strlen(delpath)] = '\0';
picpath=(char*)malloc(sizeof(char*)*(length-strlen(delpath)+strlen(picfol)+1));
strcpy(picpath,path);
strcat(picpath,picfol);
//ファイル検索
FileName=SearchFile(picpath,FindPng,&FileAmount);
//画像のロード
hpicture=(int*)malloc(sizeof(int*)*FileAmount);
for(i=0;i<FileAmount;i++){
LoadPath=(char*)malloc(sizeof(char*)*(strlen(picpath)+strlen(FileName[i])));
strcpy(LoadPath,picpath);
strcat(LoadPath,FileName[i]);
while(1){
X = strchr(LoadPath,'\\');
if(X != NULL){
*X = '/';
}
else{break;}
}
hpicture[i]=LoadGraph(LoadPath);
free(LoadPath);
}
for(i=0;i<100;i++){
//DrawStringToHandle( 0, i*10, FileName[i], GetColor( 0, 255, 0 ),CreateFontToHandle( "メイリオ",10, 1, DX_FONTTYPE_ANTIALIASING_EDGE ) ); // 文字を描画する
DrawGraph( i*20 , i*20 , hpicture[i] , FALSE ) ;
}
ScreenFlip();
WaitKey() ;
}
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定
hoge();
/*while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 ){
}*/
DxLib_End(); // DXライブラリ終了処理
return 0;
}
#include <windows.h>
#include <commctrl.h>
#include "Def_ReadData.h"
char **FileSearch(char *FolderPass,char *ExtPass){
int i,j;
//ファイル検索用
WIN32_FIND_DATA fFind;
HANDLE hSearch;
char *FindPass;
//画像名格納用
char **FileName; //ファイル名一覧格納ポインタ
char **FileName2; //ポインタサイズ変更用ポインタ
int FileNameLong=0; //ファイル名文字数
FindPass=(char*)malloc(sizeof(char*)*(strlen(FolderPass)+strlen(ExtPass)));
strcpy(FindPass,FolderPass);
strcat(FindPass,ExtPass);
hSearch=FindFirstFile(FindPass,&fFind); // 探索開始
//1個目が見つからない場合
if (hSearch==INVALID_HANDLE_VALUE) {// 見つからなければ探索終了
FindClose(hSearch);
return 0;
}
else{
i=1;
//ファイル名格納領域サイズ設定
j=0;
while(fFind.cFileName[j]!='\0'){
j++;
}
FileNameLong=j;
//配列サイズ変更
FileName2=(char**)malloc(sizeof(char*)*i);
for(j=0;j<i;j++){
FileName2[j]=(char*)malloc(sizeof(char*)*FileNameLong);
}
FileName=FileName2;
FileName2=NULL;
//ファイル名格納
strcpy(FileName[i-1],fFind.cFileName);
//残りを検索
while (FindNextFile(hSearch,&fFind)) { /* 全ファイルを処理 */
i++;
//ファイル名格納領域サイズ設定
j=0;
while(fFind.cFileName[j]!='\0'){
j++;
}
FileNameLong=j;
//配列サイズ変更
FileName2=(char**)malloc(sizeof(char*)*i);
for(j=0;j<i;j++){
FileName2[j]=(char*)malloc(sizeof(char*)*FileNameLong);
}
for(j=0;j<i-1;j++){
strcpy(FileName2[j],FileName[j]);
}
FileName=FileName2;
FileName2=NULL;
//ファイル名格納
strcpy(FileName[i-1],fFind.cFileName);
}
}
FindClose(hSearch);
return FileName;
}