#include <shellapi.h>
#pragma comment(lib,"shell32.lib")
char delpath[] = "c:\\test\\*.*\0\0";
SHFILEOPSTRUCT sf={
0, FO_DELETE, delpath, NULL,
FOF_NOCONFIRMATION+FOF_NOERRORUI,
0, 0, 0
};
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
LPSTR lpszArgument, int nFunsterStil)
{
char buf[] = "string...";
int i = 0;
SHFileOperation(&sf);
return 0;
}
/*==========================================================
- - - - - - - - - - exfile.exe - - - - - - - - - -
Building C:\download\exfile\output\main.obj.
C:\download\exfile\main.c(21): error #2139: Too many initializers.
*** Error code: 1 ***
Done.
*/
4.0b3
win2000pro
char delpath[] = "c:\\test\\*.*\0\0";
SHFILEOPSTRUCT sf;
memset(&sf, 0, sizeof(SHFILEOPSTRUCT));
sf.hwnd= NULL;
sf.wFunc = FO_DELETE;
sf.pFrom = delpath;
sf.pTo = NULL;
sf.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI;
John
3q JohnF,but why?
in shellapi.h:
typedef struct _SHFILEOPSTRUCTA {
HWND hwnd;
UINT wFunc;
LPCSTR pFrom;
LPCSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
LPCSTR lpszProgressTitle;
} SHFILEOPSTRUCTA, *LPSHFILEOPSTRUCTA;
typedef struct _SHFILEOPSTRUCTW {
HWND hwnd;
UINT wFunc;
LPCWSTR pFrom;
LPCWSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
LPCWSTR lpszProgressTitle;
} SHFILEOPSTRUCTW, *LPSHFILEOPSTRUCTW;
>but why
The compiler does not know the value of variables at compile time.
edit; I think when all C99 features are implemented it will accept that code of yours but for now you will have to do it the way I showed you.
John
here's my code, and it works well:
===============================================
typedef struct _SHFILEOPA
{
HWND hwnd;
UINT wFunc;
LPCSTR pFrom;
LPCSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
LPCSTR lpszProgressTitle; // only used if FOF_SIMPLEPROGRESS
} SHFILEOPA, FAR *LPSHFILEOPA;
typedef SHFILEOPA SHFILEOP;
static SHFILEOP sf={0, FO_DELETE, delpath, NULL,
FOF_NOCONFIRMATION+FOF_NOERRORUI,
0,0,0};
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
LPSTR lpszArgument, int nFunsterStil)
{
SHFileOperation((SHFILEOPSTRUCT*)&sf);
return 0;
)
It looks like a bug.
The file shellapi.h uses byte packing for structures. Since FILEOP_FLAGS is defined as a word, all fields after fFlags are actually unaligned. This is obviously what Microsoft wants. The initializer code for structures will not work in this case. Should be fixed in the next beta release of 4.0.
Pelle
Oh, ok. :)
John
In 4.0beta4:
typedef struct _SHFILEOPA
{
HWND hwnd;
UINT wFunc;
LPCSTR pFrom;
LPCSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
LPCSTR lpszProgressTitle; // only used if FOF_SIMPLEPROGRESS
} SHFILEOPA, FAR *LPSHFILEOPA;
typedef SHFILEOPA SHFILEOP;
static SHFILEOP sf={0, FO_DELETE, delfilepath, NULL,
FOF_NOCONFIRMATION+FOF_NOERRORUI,//FOF_ALLOWUNDO+
0,0,0};
SHFileOperation((SHFILEOPSTRUCT*)&sf);
10001BCC |. 68 D9440010 push TestSHFO.100044D9
10001BD1 |. FF15 A8480010 call dword ptr ds:[<&SHELL32.SHFileOperationA>] ;
100044D9 00 00 00 00 03 00 00 00 67 40 00 10 00 00 00 00 .......g@.....
100044E9 10 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..............
100044F9 0A 0A 5B 25 73 5D 0A 25 73 0A 0A 00 D5 30 00 10 ..[%s].%s...?.
10004509 D0 30 00 10 CE 30 00 10 CC 30 00 10 C7 30 00 10 ?.?.?.?.
static SHFILEOPSTRUCT sf={0, FO_DELETE, delfilepath, NULL,
FOF_NOCONFIRMATION+FOF_NOERRORUI,//FOF_ALLOWUNDO+
0,0,0};
SHFileOperation(&sf);
10001BCC |. 68 D9440010 push TestSHFO.100044D9
10001BD1 |. FF15 A8480010 call dword ptr ds:[<&SHELL32.SHFileOperationA>] ;
100044D9 00 00 00 00 03 00 00 00 67 40 00 10 00 00 00 00 .......g@.....
100044E9 10 04 00 00 00 00 00 00 00 00 00 00 00 00 0A 0A ..............
100044F9 5B 25 73 5D 0A 25 73 0A 0A 00 D5 30 00 10 D0 30 [%s].%s...?.?
10004509 00 10 CE 30 00 10 CC 30 00 10 C7 30 00 10 C2 30 .?.?.?.?
The answer is 42.
Actually, I have no idea what you are tring to say...
Pelle