problem using malloc in co-installer

Discussion in 'Windows Vista Drivers' started by JC, Dec 1, 2005.

  1. JC

    JC Guest

    Hello ALL,

    I wrote a co-installer software in which I also scan what devices has
    already installed in the system. Below is the source code for the scan. It
    runs fine under Win32 application. However, when I put the code in the
    co-installer. I have problems. The problem is on line "pDevIfDetail =

    The installation process exist the co-installer if I run this line and
    related code.

    Could anybody tell me why I can not use malloc in the co-installer. I really
    do not understand.

    Thanks ahead for your help. Any idea would be very helpful.


    UINT ScanInstalledDevice(

    IN UINT uMsg



    UINT intResult = 6;

    int intT;


    SP_DEVINFO_DATA DevInfo = {0};

    DWORD dwDevIndex;

    DWORD dwNeededSz;

    TCHAR fname[MAX_PATH] = {0};

    char chfname[MAX_PATH];

    char chfname_sn[MAX_PATH];


    static /*const*/ GUID GUID_MYDEVICE1 = { 0x6bdd1fc6, 0x810f, 0x11D0, { 0xbe,
    0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f } };

    HDEVINFO hDevInfoSet = SetupDiGetClassDevs(&GUID_MYDEVICE1, NULL, NULL,


    if(hDevInfoSet == INVALID_HANDLE_VALUE)


    return 0;


    DevIfData.cbSize = sizeof(DevIfData);

    for(dwDevIndex=0; SetupDiEnumDeviceInterfaces(hDevInfoSet, NULL,
    &GUID_MYDEVICE1, dwDevIndex, &DevIfData); ++dwDevIndex)


    dwNeededSz = 0;

    SetupDiGetDeviceInterfaceDetail(hDevInfoSet, &DevIfData, NULL, 0,
    &dwNeededSz, NULL);

    pDevIfDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(dwNeededSz);

    pDevIfDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);

    DevInfo.cbSize = sizeof(SP_DEVINFO_DATA);

    if(!SetupDiGetDeviceInterfaceDetail(hDevInfoSet, &DevIfData, pDevIfDetail,
    dwNeededSz, NULL, &DevInfo))


    free((PVOID) pDevIfDetail);



    if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &DevInfo,
    SPDRP_FRIENDLYNAME, NULL, (PBYTE) fname, sizeof(fname), NULL))


    WideCharToMultiByte(CP_ACP, 0, (LPWSTR)fname, MAX_PATH, chfname, MAX_PATH,
    NULL, NULL);





    return intResult;

    JC, Dec 1, 2005
    1. Advertisements

  2. Use LocalAlloc(LPTR) instead.
    Maxim S. Shatskih, Dec 1, 2005
    1. Advertisements

  3. JC

    Pavel A. Guest

    The malloc function needs some runtime support. Probably the host process in
    your coinstaller runs does not provide this support, or you link against a
    wrong C library.
    Use the low level win32 API as Maxim suggested.

    Pavel A., Dec 1, 2005
  4. JC

    JC Guest

    JC, Dec 8, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.