I need a way to verify that XXX_Open is successfully called, but there is
much more to my question...

I know that CreateFile will cause the Device Manager to call XXX_Open, and
yes, I did verify that XXX_Init is called, and my driver appears in the
registry (DLL, and Prefix values only, see below).
I use the following C# code to do this:

hInDevice = CreateFile(DeviceName.ToString(),
GENERIC_WRITE,
FILE_SHARE_WRITE,
IntPtr.Zero,
OPEN_EXISTING,
0,
IntPtr.Zero);

However, I obtain an exception upon calling CreateFile. The exception
description (from C# Exception object) is as follows:

"Can't transmit to USB port TRC1:"

The entry on WinCE (in the registry) is as folllows:

HKEY_LOCAL_MACHINE\Drivers\Active\21
Name = TRC1:
Key = Drivers\USB\ClientDrivers\SRT_DEVICE

And yes, there is an entry under ClientDrivers.


Is my driver actually loaded properly on WinCE? How can I be damn sure
that the driver is loaded properly in WinCE? Is just the fact that it
shows up in the HKEY_LOCAL_MACHINE\Drivers\Active\xx section good enough
to verify this?

Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Fri Apr 22 10:23:38 CDT 2005

I really need help on this, if anyone can respond, I would greatly
appreciate this. My device goes through the entire enumeration process
successfully. However, when I do a CreateFile, I expect XXX_Open to be
called, but it isn't. As a matter of fact, when I use the GetLastError()
function, it returns code 55 which indicates the driver was not found!!
So, I am really confused, since the driver shows up in the
HKEY_LOCAL_MACHINES\Driver\Active\xx. Please help me.


Re: XXX_Open not being called !! by Paul

Paul
Fri Apr 22 10:53:02 CDT 2005

Here's what I'd do:

1. Forget about C# for now and use C/C++. By using managed code, you've put
an extra layer between you and the driver which could easily be wrong (your
P/Invoke declaration could be bad).

2. Forget about using class libraries (like MFC or whatever). And just call
CreateFile( _T( "drivername" ), ...), rather than hiding from us what is
getting passed in the parameters. You can use the eVC new project wizard to
build you a simple console program and make CreateFile calls in the WinMain
routine. If that fails, post again with the actual code and use the Remote
Registry Editor to export the HKLM/Drivers/Active branch of the registry and
post that, too.

Paul T.

"jamestheDork" <jamesevangelos@yahoo.com> wrote in message
news:c6b9e12913711d623ee19bbe329ee66d@localhost.talkaboutsoftware.com...
>I really need help on this, if anyone can respond, I would greatly
> appreciate this. My device goes through the entire enumeration process
> successfully. However, when I do a CreateFile, I expect XXX_Open to be
> called, but it isn't. As a matter of fact, when I use the GetLastError()
> function, it returns code 55 which indicates the driver was not found!!
> So, I am really confused, since the driver shows up in the
> HKEY_LOCAL_MACHINES\Driver\Active\xx. Please help me.
>



Re: XXX_Open not being called !! by Steve

Steve
Fri Apr 22 10:51:14 CDT 2005

1) Use the kernel debugger and step through the call to CreateFile() to see
why it is failing.
2) Use the debug zones in DeviceManager to see what is happening...

--
Steve Maillet
EmbeddedFusion
www.EmbeddedFusion.com
smaillet at EmbeddedFusion dot com



Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Sun Apr 24 17:02:54 CDT 2005

Dear Mr. Tobey I tried instructions #1 and #2 in your previous post. This
did not work. Per your instructions I am posting my code here along with
the registry export:

Client code that calls CreateFile:

HANDLE hOutDevice;
SetLastError(0);

//COM0: returns the most promising results. -- 0 ERROR_SUCCESS
//TRC1: -- error 55 ERROR_DEV_NOT_EXIST
//GEN1: returns 0, ERROR_SUCCESS as well !
hOutDevice = CreateFile(
TEXT("TRC1:"),
GENERIC_WRITE | GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
0,
NULL);

int iVal = GetLastError();

REGISTRY EXPORT:

REGEDIT4

[HKEY_LOCAL_MACHINE\Drivers\Active\21]
"Hnd"=dword:0004f030
"Name"="TRC1:"
"Key"="Drivers\\USB\\SRT_DEVICE"
"ClientInfo"=dword:00036940

Please help me, I will provide as much info as you need.


Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Mon Apr 25 10:59:01 CDT 2005

I use Embedded Visual C++ to step through the CreateFile code. See my
reply to Paul Tobey to see my source code. I get an error code back as
explained therein. So, I sort of know why it is failing, see the response
to Paul Tobey.

As far as Debug Zones are concerned, I have been unsuccessful in using
Debug Zones on CEPB 4.2 for some reason. When I go to turn Debug Zones
"on" the item never gets un-greyed out from the menu.


Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Mon Apr 25 11:41:25 CDT 2005

Someone please help me with the previous post! Any help would be
appreciated, but please read my previous posts carefully. If I find the
answer, I will post it.


Re: XXX_Open not being called !! by Paul

Paul
Mon Apr 25 14:39:53 CDT 2005

OK, that looks fine, or, at least nothing just leaps out at me. What is in
the main registry entry for the device (HKLM/Drivers/USB/SRT_Device)? You
might take this opportunity to verify that DriverEntry(), XXX_Init, etc. are
all returning correct values to their callers. Can you show the driver
source for the Open implementation and the DEF file?

Paul T.

"jamestheDork" <jamesevangelos@yahoo.com> wrote in message
news:4cbb35de06904342a00032cd5f01fd4a@localhost.talkaboutsoftware.com...
> Someone please help me with the previous post! Any help would be
> appreciated, but please read my previous posts carefully. If I find the
> answer, I will post it.
>



Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Mon Apr 25 15:52:55 CDT 2005

Thanks so much Paul, ok here is the info:

1. Registry entries (in project.reg file)

[HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients\5844_4098\Default\Default\SRT_DEVICE]
"DLL"="TxRx.dll"
"Prefix"="TRC"

[HKEY_LOCAL_MACHINE\Drivers\USB\SRT_DEVICE]
"Index"=dword:1
"DeviceArrayIndex"=dword:0
"Prefix"="TRC"
"Dll"="TxRx.dll"

It seems DllMain and TRC_Init are returning the proper values.

2. TRC_Open function:

PUSBTRC_CONTEXT TRC_Open( PUSBTRC_CONTEXT Context, // context
returned by TRC_Init.
DWORD AccessCode, // @parm access code
DWORD ShareMode // @parm share mode
)
{
PUSBTRC_CONTEXT pUsbTrc = Context;
BOOL bRc = TRUE;

UNREFERENCED_PARAMETER(ShareMode);
UNREFERENCED_PARAMETER(AccessCode);

DEBUGMSG(ZONE_TRC_INIT,(TEXT(">TRC_Open(0x%x, 0x%x, 0x%x)\n"),pUsbTrc,
AccessCode, ShareMode));

if ( VALID_CONTEXT( pUsbTrc ) )
{
EnterCriticalSection(&pUsbTrc->Lock);
if ( !pUsbTrc->Flags.Open && !pUsbTrc->Flags.UnloadPending )
{
pUsbTrc->Flags.Open = TRUE;
ResetEvent( pUsbTrc->hCloseEvent ); // non-signaled
}
else
{
DEBUGMSG( ZONE_ERR,(TEXT("TRC_Open: ERROR_ACCESS_DENIED\n")));
SetLastError(ERROR_ACCESS_DENIED);
bRc = FALSE;
}
LeaveCriticalSection(&pUsbTrc->Lock);
}
else
{
DEBUGMSG( ZONE_ERR,(TEXT("TRC_Open: ERROR_FILE_NOT_FOUND\n")));
SetLastError(ERROR_FILE_NOT_FOUND);
bRc = FALSE;
}

DEBUGMSG(ZONE_TRC_INIT,(TEXT("<TRC_Open:%d\n"), bRc ));

return (bRc ? pUsbTrc : NULL);
}

3. Contents of *.def file:
LIBRARY TXRX_LIB

EXPORTS
DllMain
TRC_Init
TRC_Deinit
TRC_Open
TRC_Close
TRC_Read
TRC_Write
USBDeviceAttach
USBInstallDriver
USBUnInstallDriver




Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Mon Apr 25 16:24:19 CDT 2005

Thanks so much Paul, ok here is the info:

1. Registry entries (in project.reg file)

[HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients\5844_4098\Default\Default\SRT_DEVICE]
"DLL"="TxRx.dll"
"Prefix"="TRC"

[HKEY_LOCAL_MACHINE\Drivers\USB\SRT_DEVICE]
"Index"=dword:1
"DeviceArrayIndex"=dword:0
"Prefix"="TRC"
"Dll"="TxRx.dll"

It seems DllMain and TRC_Init are returning the proper values.

2. TRC_Open function:

PUSBTRC_CONTEXT TRC_Open( PUSBTRC_CONTEXT Context, // context
returned by TRC_Init.
DWORD AccessCode, // @parm access code
DWORD ShareMode // @parm share mode
)
{
PUSBTRC_CONTEXT pUsbTrc = Context;
BOOL bRc = TRUE;

UNREFERENCED_PARAMETER(ShareMode);
UNREFERENCED_PARAMETER(AccessCode);

DEBUGMSG(ZONE_TRC_INIT,(TEXT(">TRC_Open(0x%x, 0x%x, 0x%x)\n"),pUsbTrc,
AccessCode, ShareMode));

if ( VALID_CONTEXT( pUsbTrc ) )
{
EnterCriticalSection(&pUsbTrc->Lock);
if ( !pUsbTrc->Flags.Open && !pUsbTrc->Flags.UnloadPending )
{
pUsbTrc->Flags.Open = TRUE;
ResetEvent( pUsbTrc->hCloseEvent ); // non-signaled
}
else
{
DEBUGMSG( ZONE_ERR,(TEXT("TRC_Open: ERROR_ACCESS_DENIED\n")));
SetLastError(ERROR_ACCESS_DENIED);
bRc = FALSE;
}
LeaveCriticalSection(&pUsbTrc->Lock);
}
else
{
DEBUGMSG( ZONE_ERR,(TEXT("TRC_Open: ERROR_FILE_NOT_FOUND\n")));
SetLastError(ERROR_FILE_NOT_FOUND);
bRc = FALSE;
}

DEBUGMSG(ZONE_TRC_INIT,(TEXT("<TRC_Open:%d\n"), bRc ));

return (bRc ? pUsbTrc : NULL);
}

3. Contents of *.def file:
LIBRARY TXRX_LIB

EXPORTS
DllMain
TRC_Init
TRC_Deinit
TRC_Open
TRC_Close
TRC_Read
TRC_Write
USBDeviceAttach
USBInstallDriver
USBUnInstallDriver




Re: XXX_Open not being called !! by Paul

Paul
Mon Apr 25 16:39:42 CDT 2005

I don't see any problems with that. It would be good, generally, not to
count on a read of platform.reg for what's actually in the registry. As a
check, you should export that section of the registry via Remote Registry
Editor, as I assume you did with the Active branch.

If you change your first DEBUGMSG in the Open routine so that you'll always
get the text out, does that make any difference (you're building a DEBUG
build, right?)? RETAILMSG( 1, (TEXT(...) ) ); is what I'd try to be sure.

The Init function is returning a non-zero value?

You might try having the power functions declared in your driver: PowerUp
and PowerDown.

Paul T.

"jamestheDork" <jamesevangelos@yahoo.com> wrote in message
news:c99396a769beb920e4578235588c00de@localhost.talkaboutsoftware.com...
> Thanks so much Paul, ok here is the info:
>
> 1. Registry entries (in project.reg file)
>
> [HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients\5844_4098\Default\Default\SRT_DEVICE]
> "DLL"="TxRx.dll"
> "Prefix"="TRC"
>
> [HKEY_LOCAL_MACHINE\Drivers\USB\SRT_DEVICE]
> "Index"=dword:1
> "DeviceArrayIndex"=dword:0
> "Prefix"="TRC"
> "Dll"="TxRx.dll"
>
> It seems DllMain and TRC_Init are returning the proper values.
>
> 2. TRC_Open function:
>
> PUSBTRC_CONTEXT TRC_Open( PUSBTRC_CONTEXT Context, // context
> returned by TRC_Init.
> DWORD AccessCode, // @parm access code
> DWORD ShareMode // @parm share mode
> )
> {
> PUSBTRC_CONTEXT pUsbTrc = Context;
> BOOL bRc = TRUE;
>
> UNREFERENCED_PARAMETER(ShareMode);
> UNREFERENCED_PARAMETER(AccessCode);
>
> DEBUGMSG(ZONE_TRC_INIT,(TEXT(">TRC_Open(0x%x, 0x%x, 0x%x)\n"),pUsbTrc,
> AccessCode, ShareMode));
>
> if ( VALID_CONTEXT( pUsbTrc ) )
> {
> EnterCriticalSection(&pUsbTrc->Lock);
> if ( !pUsbTrc->Flags.Open && !pUsbTrc->Flags.UnloadPending )
> {
> pUsbTrc->Flags.Open = TRUE;
> ResetEvent( pUsbTrc->hCloseEvent ); // non-signaled
> }
> else
> {
> DEBUGMSG( ZONE_ERR,(TEXT("TRC_Open: ERROR_ACCESS_DENIED\n")));
> SetLastError(ERROR_ACCESS_DENIED);
> bRc = FALSE;
> }
> LeaveCriticalSection(&pUsbTrc->Lock);
> }
> else
> {
> DEBUGMSG( ZONE_ERR,(TEXT("TRC_Open: ERROR_FILE_NOT_FOUND\n")));
> SetLastError(ERROR_FILE_NOT_FOUND);
> bRc = FALSE;
> }
>
> DEBUGMSG(ZONE_TRC_INIT,(TEXT("<TRC_Open:%d\n"), bRc ));
>
> return (bRc ? pUsbTrc : NULL);
> }
>
> 3. Contents of *.def file:
> LIBRARY TXRX_LIB
>
> EXPORTS
> DllMain
> TRC_Init
> TRC_Deinit
> TRC_Open
> TRC_Close
> TRC_Read
> TRC_Write
> USBDeviceAttach
> USBInstallDriver
> USBUnInstallDriver
>
>
>



Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Mon Apr 25 17:00:39 CDT 2005

I will try your suggestions, but curious, what would power functions buy
me?


Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Mon Apr 25 17:03:08 CDT 2005

I will try your suggestions, but curious, what would power functions buy
me?


Re: XXX_Open not being called !! by Paul

Paul
Mon Apr 25 17:09:51 CDT 2005

In other drivers I've written, the presence of power functions was required,
whether they did anything or not. They can be empty.

Paul T.

"jamestheDork" <jamesevangelos@yahoo.com> wrote in message
news:9f263677e49beb8c6fd09e87b9914bf9@localhost.talkaboutsoftware.com...
>I will try your suggestions, but curious, what would power functions buy
> me?
>



Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Tue Apr 26 12:02:17 CDT 2005

Paul, I followed your instructions as follows:

1. I checked the registry and it checks out as follows:
[HKEY_LOCAL_MACHINE\Drivers\USB\SRT_DEVICE]
"Index"=dword:1
"DeviceArrayIndex"=dword:0
"Prefix"="TRC"
"Dll"="TxRx.dll"

2. The TRC_Init function returns a pointer to a structure. The pointer
gets memory allocated and in effect TRC_Init returns a non-zero value. So
it should be properly initialized! I include the code for TRC_Init below:

DWORD TRC_Init (DWORD dwContext, LPCVOID lpvBusContext)
{
LPTSTR ActivePath = (LPTSTR)dwContext; // HKLM\Drivers\Active\xx
PUSBTRC_CONTEXT pDrvCtxt = NULL;
BOOL bRc = FALSE;

DEBUGMSG (ZONE_INIT, (TEXT("TRC_Init++ dwContex:%x\r\n"),
dwContext));

// Allocate a device instance structure.
pDrvCtxt = (PUSBTRC_CONTEXT)LocalAlloc (LPTR, sizeof
(USBTRC_CONTEXT));
if (pDrvCtxt)
{
// get our Context, which is the "Key" value which should show up as
// Drivers\Builtin\SRT_Device.
// The ActivePath should show up as
HKEY_LOCAL_MACHINE\Drivers\Active\xx
// note, in our tests I have seen it assigned as device 08 for xx.
memset ((PBYTE) pDrvCtxt, 0, sizeof (USBTRC_CONTEXT));
pDrvCtxt = (PUSBTRC_CONTEXT)UsbsGetContextFromReg( ActivePath );
}
else
{
DEBUGMSG (ZONE_INIT | ZONE_ERR, (TEXT("TRC_Init failure. Out of
memory\r\n")));
}

return (DWORD)pDrvCtxt;
}

I used to have a function that registers the device inside the TRC_Init
function. Is this absolutely necessary?


Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Tue Apr 26 12:22:29 CDT 2005

Also, in spite of making the changes (see my last post) I still have the
problem of GetLastError returning code 55 (unrecognized device). Please
be patient, and keep helping me with this. Thanks!


Re: XXX_Open not being called !! by Paul

Paul
Tue Apr 26 12:40:28 CDT 2005

It's not testing my patience, just my list of ideas of what's going on. I
don't know, for example, if you have to register the device in Init or
not...

Paul T.

"jamestheDork" <jamesevangelos@yahoo.com> wrote in message
news:b5554804f21d087c5ed55da66e5737f9@localhost.talkaboutsoftware.com...
> Also, in spite of making the changes (see my last post) I still have the
> problem of GetLastError returning code 55 (unrecognized device). Please
> be patient, and keep helping me with this. Thanks!
>



Re: XXX_Open not being called !! by Steve

Steve
Tue Apr 26 13:11:48 CDT 2005

What device would you register in the Init function? Certainly not the TRC
one as it's already registered if the init function is being called... Hmm
wait. Are you calling the _Init function directly from the USB portion of
the driver? Does your USB portion call ActivateDeviceEx to load the stream
interface?

--
Steve Maillet
EmbeddedFusion
www.EmbeddedFusion.com
smaillet at EmbeddedFusion dot com



Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Tue Apr 26 13:51:48 CDT 2005

Thanks Paul!! It is really good to get so muich help!

Ok, For the first part of your reply, I guess I am unsure as to what
exactly the XXX_Init function is intended to do. In the COMMON\OAK
directory, I found code correspoding to a USB printer driver, and my
XXX_Init stream function largely borrows that code. Inside that Init they
make a call to a RegisterPRNName, which I change to RegisterTRCName.

For the second part of your statement, YES! I created a function called
USBDeviceAttach, which in turn calls ActivateDevice (not the Ex version).
USBDeviceAttach is exported from my Dll. I thought that this should be
ok?

Yes, I have a USBDeviceAttach function that is defined in the driver. As
I understand it, when WinCE boots the DM calls this function, which in
turn calls ActivateDevice (not the Ex version).


Re: XXX_Open not being called !! by Steve

Steve
Tue Apr 26 14:21:18 CDT 2005

Let's re-cap some things:
1) USBDeviceAttach calls ActivateDevice( _T("Drivers\USB\SRT_DEVICE")) (Does
this return a non zero handle?)
2) TRC_Init is called (By what means is that verified?)
3) Does the TRC driver show up under HKLM\Drivers\Active\xx some where?
(I've looked through your posts that are available to me on the server and
don't see anything on that.)

Have you tried to step through the CreateFile call with Platform Builder and
the kernel debugger? That would tell you pretty quickly what is actually
going on and why an error is returned. (Note the first part of the
CreateFile Call will give you a disassembly view of the code, don't worry
about that it will shortly get back to source code again as long as you
installed the shared source.)

--
Steve Maillet
EmbeddedFusion
www.EmbeddedFusion.com
smaillet at EmbeddedFusion dot com



Re: XXX_Open not being called !! by jamestheDork

jamestheDork
Thu Apr 28 08:02:48 CDT 2005

Steve, I have addressed each of your items below:

1) Yes, ActivateDevice, called in USBDev