NO

Author Topic: SHFILEOPSTRUCT bug  (Read 6419 times)

guest

  • Guest
SHFILEOPSTRUCT bug
« on: August 28, 2005, 09:59:42 AM »
#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

JohnF

  • Guest
SHFILEOPSTRUCT bug
« Reply #1 on: August 28, 2005, 10:48:31 AM »
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

guest

  • Guest
SHFILEOPSTRUCT bug
« Reply #2 on: August 28, 2005, 02:56:12 PM »
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;

JohnF

  • Guest
SHFILEOPSTRUCT bug
« Reply #3 on: August 28, 2005, 04:07:30 PM »
>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

guest

  • Guest
SHFILEOPSTRUCT bug
« Reply #4 on: August 28, 2005, 04:29:01 PM »
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;
)

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
SHFILEOPSTRUCT bug
« Reply #5 on: August 28, 2005, 09:28:21 PM »
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
/Pelle

JohnF

  • Guest
SHFILEOPSTRUCT bug
« Reply #6 on: August 28, 2005, 10:56:56 PM »
Oh, ok. :)

John

guest

  • Guest
SHFILEOPSTRUCT bug
« Reply #7 on: September 11, 2005, 08:04:58 PM »
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  .?.?.?.?

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
SHFILEOPSTRUCT bug
« Reply #8 on: September 12, 2005, 05:24:42 PM »
The answer is 42.

Actually, I have no idea what you are tring to say...

Pelle
/Pelle