Need help in coinstaller

Hi,

I have written a coinstaller which open the device handle at the init and destroys at exit. The problem is that the device handle overwrites the previous handle when the multiple instance of the same device is accessed. I want to know how to store per data instance . I want to know how to store private data in the coinstaller. I would appreciate if anyone explains me with an example.

Regards,
Srinivasa Raghavan.

On Thu, Dec 25, 2008 at 02:18:15PM -0500, xxxxx@yahoo.com wrote:

Hi,

I have written a coinstaller which open the device handle at the init
and destroys at exit. The problem is that the device handle overwrites
the previous handle when the multiple instance of the same device is
accessed. I want to know how to store per data instance . I want to
know how to store private data in the coinstaller. I would appreciate
if anyone explains me with an example.

Did you notice the COINSTALLER_CONTEXT_DATA structure that gets passed
to your coinstaller entry point? Did you notice that it contains a
PrivateData pointer?

Tim Roberts, xxxxx@probo.com
Providenza & Boeklheide, Inc.

Hi Tim Roberts,

Thank you very much for your reply.

Yes, I know PrivateData pointer, but I dont know how to use it.

Let me explain my problem, I have written a coinstaller for a ethernet card, the card support’s multiport.

The way I tried.

Context->PrivateData = params;

params = (DEVICE_PROP_PARAMS *)
HeapAlloc(GetProcessHeap(), 0, sizeof(DEVICE_PROP_PARAMS));
if (params)
{
params->DeviceInfoSet = DeviceInfoSet;
params->DeviceInfoData = DeviceInfoData;
params->Restart = FALSE;
params->g1Device = g1Device; // g1Device is defined as Global variable handle
}
/* Create/Open the Handle to device File */
g1Device = GuidCreateDevice(deviceGUID); // GuidCreateDevice -> calls CreateDevice() fn.
// deviceGUID -> Device Instance.

The older handle is replaced by the new one when new instance is called. I am creating the handle in DIF_ADDPROPERTYPAGE_ADVANCED and closing the handle it in DIF_DESTROYPRIVATEDATA.

Please let me know where I am doing wrong and what is exact way to implement?

Thanks in Advance,
Srinivasa Raghavan.

If you are posting your code as is, you assigning params

Context->PrivateData = params;

Before you allocate the memory

params = (DEVICE_PROP_PARAMS *)
HeapAlloc(GetProcessHeap(), 0, sizeof(DEVICE_PROP_PARAMS));

Move the assignment PrivateData after you have allocated and initialized your struct

d

Sent from my phone with no t9, all spilling mistakes are not intentional.

-----Original Message-----
From: xxxxx@yahoo.com
Sent: Sunday, December 28, 2008 8:13 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Need help in coinstaller

Hi Tim Roberts,

Thank you very much for your reply.

Yes, I know PrivateData pointer, but I dont know how to use it.

Let me explain my problem, I have written a coinstaller for a ethernet card, the card support’s multiport.

The way I tried.
==========

Context->PrivateData = params;

params = (DEVICE_PROP_PARAMS )
HeapAlloc(GetProcessHeap(), 0, sizeof(DEVICE_PROP_PARAMS));
if (params)
{
params->DeviceInfoSet = DeviceInfoSet;
params->DeviceInfoData = DeviceInfoData;
params->Restart = FALSE;
params->g1Device = g1Device; // g1Device is defined as Global variable handle
}
/
Create/Open the Handle to device File */
g1Device = GuidCreateDevice(deviceGUID); // GuidCreateDevice -> calls CreateDevice() fn.
// deviceGUID -> Device Instance.

The older handle is replaced by the new one when new instance is called. I am creating the handle in DIF_ADDPROPERTYPAGE_ADVANCED and closing the handle it in DIF_DESTROYPRIVATEDATA.

Please let me know where I am doing wrong and what is exact way to implement?

Thanks in Advance,
Srinivasa Raghavan.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hi Doron Holan,

Thanks and Nice to see your reply. I did as per you suggestions, but the issu remains the same.

And one more, I added around 3 tabs in the coinstaller, all the tabs need the device handle to be passed as parameter.

/* Create/Open the Handle to device File */
g1Device = GuidCreateDevice(deviceGUID); // GuidCreateDevice -> calls

params = (DEVICE_PROP_PARAMS *)
HeapAlloc(GetProcessHeap(), 0, sizeof(DEVICE_PROP_PARAMS));

if (params)
{
params->DeviceInfoSet = DeviceInfoSet;
params->DeviceInfoData = DeviceInfoData;
params->Restart = FALSE;
params->g1Device = g1Device;

Context->PrivateData = params->g1Device;

g1Device = Context->PrivateData;

memset(&page, 0, sizeof(PROPSHEETPAGE));

#ifndef hp

page.dwSize = sizeof(PROPSHEETPAGE);
page.dwFlags = PSP_USECALLBACK;
page.hInstance = ModuleInstance;
page.pszTemplate = MAKEINTRESOURCE(DLG_NX_INFO);
page.pfnDlgProc = (DLGPROC)PropPageDlgProcInfo;
page.pfnCallback = PropPageDlgCallback;
page.lParam = (LPARAM)Context->PrivateData;

sprintf(str, “Addprop = %x\n”, (LONG_PTR)g1Device);
OutputDebugStringA(str);

/* Create Information Property Sheet */
pageHandle[count] = CreatePropertySheetPage(&page);

if(!pageHandle[count])
{
nxTraceLogError(“: [Info] Property Sheet not Created\0”, ERROR_LOG);
HeapFree(GetProcessHeap(), 0, params);
return NX_ERROR;
}

xxxxx@yahoo.com wrote:

Thanks and Nice to see your reply. I did as per you suggestions, but the issu remains the same.

And one more, I added around 3 tabs in the coinstaller, all the tabs need the device handle to be passed as parameter.

I begin to suspect you have several issues here. The
Context->PrivateData member will allow to maintain context information
throughout the installation of a single device. But, as I recall, you
originally said something about handling multiple devices, and sharing
state data between those installations. Is that really what you are
trying to do?

That is a very tricky problem, because you have no guarantee that the
co-installer will remain in memory. Depending on timing, the DLL might
be unloaded and then reloaded. If you need to maintain some kind of
persistent data about multiple devices, I think you are going to have to
use the registry or a disk file.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

On Mon, Dec 29, 2008 at 11:17 PM, Tim Roberts wrote:

> I begin to suspect you have several issues here. The
> Context->PrivateData member will allow to maintain context information
> throughout the installation of a single device. But, as I recall, you
> originally said something about handling multiple devices, and sharing
> state data between those installations. Is that really what you are
> trying to do?
>
> That is a very tricky problem, because you have no guarantee that the
> co-installer will remain in memory. Depending on timing, the DLL might
> be unloaded and then reloaded. If you need to maintain some kind of
> persistent data about multiple devices, I think you are going to have to
> use the registry or a disk file.
>
>
Is not the case that Context area is different for each instance of device?
Or can’t we have thread specific memory allocation when DLL thread is
created at the time of property sheet invocation?


Ashish Purkar

Ashish Purkar wrote:

Is not the case that Context area is different for each instance of
device?

Yes. Well, for each instance of the co-installer, which should be one
per device. I thought your problem was that you wanted to communicate
data between multiple instances of the co-installer? Perhaps you should
go back to the beginning and refresh us on what PROBLEM you are really
encountering.

Or can’t we have thread specific memory allocation when DLL thread is
created at the time of property sheet invocation?

There are no guarantees that each instance will be called on its own
thread, nor even that a single device will always have its callbacks on
the same thread. Don’t use thread-local storage for this.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.