Implementing DLL in UMDF

Hi,

I’m trying to implement a timer in a UMDF driver.

for that I’m using the timeSetEvent form the MMsystem.h

unfortunately I’m getting a linker error “indentifier not found”.

i think the problem is the missing of the dll winmm.dll.

How can i link it to the project so the compiler will found it ?

Thanks.

Link against the lib from which the API is exported from? The MSDN doc page should give you the lib name

d

debt from my phone

-----Original Message-----
From: xxxxx@gmail.com
Sent: Thursday, June 30, 2011 7:32 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Implementing DLL in UMDF

Hi,

I’m trying to implement a timer in a UMDF driver.

for that I’m using the timeSetEvent form the MMsystem.h

unfortunately I’m getting a linker error “indentifier not found”.

i think the problem is the missing of the dll winmm.dll.

How can i link it to the project so the compiler will found it ?

Thanks.


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,

Thanks for your answer.

I’m trying to link the Lib \ Dll which are documented in the MSDN .

in the timeSetEevent case it’s the Winmm.lib \ Winmm.dll.

I get the followed compiler error:

  1. error C2065 : ‘TIME_PERIODIC’ : undeclared identifier
  2. error C3861 : ‘timeSetEvent’: identifier not found

both relate the timeSetEevent and exist in MmSystems.h (and in windows.h)

And these are followed by the linker error:

link : error LNK1181: cannot open input file ‘c:\driverdevelop\virtual_my_chan
ge\virtualserial\objchk_win7_x86\i386\device.obj’
BUILD: Compile errors: not linking c:\driverdevelop\virtual_my_change\virtualser
ial directory

i assumed that these errors are since the compiler doesn’t know the dll \lib.

Any comments are welcome.

thanks.

This error

link : error LNK1181: cannot open input file ‘c:\driverdevelop\virtual_my_chan
ge\virtualserial\objchk_win7_x86\i386\device.obj’

Is because of this error

. error C2065 : ‘TIME_PERIODIC’ : undeclared identifier
2. error C3861 : ‘timeSetEvent’: identifier not found

You are not yet a point where linking can work. Is your file a cpp file? If yes, wrap the include of mmsystem.h in an extern “c”

d

debt from my phone

-----Original Message-----
From: xxxxx@gmail.com
Sent: Sunday, July 03, 2011 5:24 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Implementing DLL in UMDF

Hi Doron,

Thanks for your answer.

I’m trying to link the Lib \ Dll which are documented in the MSDN .

in the timeSetEevent case it’s the Winmm.lib \ Winmm.dll.

I get the followed compiler error:

  1. error C2065 : ‘TIME_PERIODIC’ : undeclared identifier
  2. error C3861 : ‘timeSetEvent’: identifier not found

both relate the timeSetEevent and exist in MmSystems.h (and in windows.h)

And these are followed by the linker error:

link : error LNK1181: cannot open input file ‘c:\driverdevelop\virtual_my_chan
ge\virtualserial\objchk_win7_x86\i386\device.obj’
BUILD: Compile errors: not linking c:\driverdevelop\virtual_my_change\virtualser
ial directory

i assumed that these errors are since the compiler doesn’t know the dll \lib.

Any comments are welcome.

thanks.


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,

Your answer helped a lot ! the problem really was the export “C”.

However, the linker is still unsatisfied and the error message is:

error LNK2019: unresolved external symbol __imp__timeSetEvent@20 referenced in function “public:
virtual long __stdcall CMyDevice::OnSelfManagedIoInit(struct IWDFDevice *)” (?O
xxxxx@CMyDevice@@UAGJPAUIWDFDevice@@@Z)

1>c:\driverdevelop\virtual_my_change\virtualserial\objchk_win7_x86\i386\virtuals
erial.dll : error LNK1120: 1 unresolved externals

Does this problem is because the missing of the lib file ?

If yes, how can i supply it to the linker ?

Thanks.

What dos your sources file look like? Ot is this in VS? Could be a mismatch between cdecl and stdcall if the project is in VS

d

debt from my phone

-----Original Message-----
From: xxxxx@gmail.com
Sent: Monday, July 04, 2011 6:21 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Implementing DLL in UMDF

Hi Doron,

Your answer helped a lot ! the problem really was the export “C”.

However, the linker is still unsatisfied and the error message is:

error LNK2019: unresolved external symbol __imp__timeSetEvent@20 referenced in function “public:
virtual long __stdcall CMyDevice::OnSelfManagedIoInit(struct IWDFDevice *)” (?O
xxxxx@CMyDevice@@UAGJPAUIWDFDevice@@@Z)

1>c:\driverdevelop\virtual_my_change\virtualserial\objchk_win7_x86\i386\virtuals
erial.dll : error LNK1120: 1 unresolved externals

Does this problem is because the missing of the lib file ?

If yes, how can i supply it to the linker ?

Thanks.


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

> both relate the timeSetEevent and exist in MmSystems.h (and in windows.h)

And these are followed by the linker error:

link : error LNK1181: cannot open input file ‘c:\driverdevelop\virtual_my_chan
ge\virtualserial\objchk_win7_x86\i386\device.obj’

Can you include the .H file and the .LIB file to your project? winmm.lib and IIRC mmsystem.h


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Hi,

Doron,
i’m not working with VS. only as Editor, the compilation is made with the
Build environment from the WDK, so i don’t see a reason for the Mismatch.

Maxim,
that’s exactly what I’m trying to find, how do i include a Lib in a project not with VS but with a code command.

thanks a lot.

It sounds like you have neglected to put the appropriate library in the
linker command.

RTFM. timeSetEvent CLEARLY states that it is found in winmm.lib. Did you
add this library to your linking step? If not, then the message is correct.

Note that a mismatch between cdecl and stdcall applies whether the project
is in VS or any other possible build. These are properties of the language,
not the system in which the code is built. But this is unlikely, since the
error message clearly shows it is trying to call a stdcall function, which
is the correct function to call.

What is odd is that there is no similar error message for timeKillEvent.
Your cleanup code should be calling this to kill the timer.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Monday, July 04, 2011 10:22 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Implementing DLL in UMDF

What dos your sources file look like? Ot is this in VS? Could be a mismatch
between cdecl and stdcall if the project is in VS

d

debt from my phone

-----Original Message-----
From: xxxxx@gmail.com
Sent: Monday, July 04, 2011 6:21 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Implementing DLL in UMDF

Hi Doron,

Your answer helped a lot ! the problem really was the export “C”.

However, the linker is still unsatisfied and the error message is:

error LNK2019: unresolved external symbol __imp__timeSetEvent@20 referenced
in function “public:
virtual long __stdcall CMyDevice::OnSelfManagedIoInit(struct IWDFDevice *)”
(?O
xxxxx@CMyDevice@@UAGJPAUIWDFDevice@@@Z)

1>c:\driverdevelop\virtual_my_change\virtualserial\objchk_win7_x86\i386\
1>virtuals
erial.dll : error LNK1120: 1 unresolved externals

Does this problem is because the missing of the lib file ?

If yes, how can i supply it to the linker ?

Thanks.


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


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


This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.

Like I asked last time, post your sources file.

d

debt from my phone

-----Original Message-----
From: xxxxx@gmail.com
Sent: Tuesday, July 05, 2011 5:06 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Implementing DLL in UMDF

Hi,

Doron,
i’m not working with VS. only as Editor, the compilation is made with the
Build environment from the WDK, so i don’t see a reason for the Mismatch.

Maxim,
that’s exactly what I’m trying to find, how do i include a Lib in a project not with VS but with a code command.

thanks a lot.


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

xxxxx@gmail.com wrote:

Hi,

Doron,
i’m not working with VS. only as Editor, the compilation is made with the
Build environment from the WDK, so i don’t see a reason for the Mismatch.

Have you shown us your sources file? Did you add winmm.lib to the
library list?

that’s exactly what I’m trying to find, how do i include a Lib in a project not with VS but with a code command.

In sources:
TARGETLIBS = $(SDK_LIB_PATH)\winmm.lib


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

Hi,

this is the Source:

HRESULT
CMyDevice::OnSelfManagedIoInit(
__in IWDFDevice * pWdfDevice
)
{
UNREFERENCED_PARAMETER(pWdfDevice);

HRESULT hr = S_OK;
//Create Timer !!
UINT interval =1000; //the interval in mS
// Start Timer !!
timerId=timeSetEvent(interval,10,TimerCallback,0,TIME_PERIODIC);
return hr;
}

HRESULT
CMyDevice::OnSelfManagedIoSuspend(
__in IWDFDevice * pWdfDevice)
{
UNREFERENCED_PARAMETER(pWdfDevice);

//Stop Timer !!!
timeKillEvent(timerId);
return S_OK;
}

of course the same happens with timeKillEvent…

thanks.

Your SOURCES (note the trailing S) file, not your source (note the lack of said trailing S) file(s).

d

debt from my phone

-----Original Message-----
From: xxxxx@gmail.com
Sent: Wednesday, July 06, 2011 3:36 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Implementing DLL in UMDF

Hi,

this is the Source:

HRESULT
CMyDevice::OnSelfManagedIoInit(
__in IWDFDevice * pWdfDevice
)
{
UNREFERENCED_PARAMETER(pWdfDevice);

HRESULT hr = S_OK;
//Create Timer !!
UINT interval =1000; //the interval in mS
// Start Timer !!
timerId=timeSetEvent(interval,10,TimerCallback,0,TIME_PERIODIC);
return hr;
}

HRESULT
CMyDevice::OnSelfManagedIoSuspend(
__in IWDFDevice * pWdfDevice)
{
UNREFERENCED_PARAMETER(pWdfDevice);

//Stop Timer !!!
timeKillEvent(timerId);
return S_OK;
}

of course the same happens with timeKillEvent…

thanks.


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 friends

I’m having the same problem. I tried to include de lib in SOUCES but it doesnt work.

I generated my DLL using Visual C++ 2010, 32bits. But, I’m using Win7 64bits.

would it be the problem.

thanks

xxxxx@gmail.com wrote:

Hi friends

I’m having the same problem.

What problem?

I tried to include de lib in SOUCES but it doesnt work.

It doesn’t BUILD or it doesn’t LOAD?

I generated my DLL using Visual C++ 2010, 32bits. But, I’m using Win7 64bits.

A 64-bit process can only load 64-bit DLLs.


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

Hi Tim

It doesnt load.

See code below:

typedef double (*importFunction)();
.
.
.

HINSTANCE hinstLib =
LoadLibraryEx(TEXT(“C:\Windows\System32\GerarDLL.dll”),NULL,LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE);
.
.
.

importFunction addNumbers;
addNumbers = (importFunction)GetProcAddress(hinstLib, MyFunction");

//////////////////////////////////

With I try to use LoadLibrary(), hinstlib is NULL. If I try to use
LoadLibraryEx, hinstlib has a value, though addNumber is null.

Which means, I believe that I can load the dll, but cant load the methods.

Regards,

Silvio S Silva

On Tue, Aug 2, 2011 at 3:24 PM, Tim Roberts wrote:

> xxxxx@gmail.com wrote:
> > Hi friends
> >
> > I’m having the same problem.
>
> What problem?
>
> > I tried to include de lib in SOUCES but it doesnt work.
>
> It doesn’t BUILD or it doesn’t LOAD?
>
> > I generated my DLL using Visual C++ 2010, 32bits. But, I’m using Win7
> 64bits.
>
> A 64-bit process can only load 64-bit DLLs.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> 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
>

Silvio Silva wrote:

It doesnt load.

See code below:

typedef double (*importFunction)();

HINSTANCE hinstLib =
LoadLibraryEx(TEXT(“C:\Windows\System32\GerarDLL.dll”),NULL,LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE);

importFunction addNumbers;
addNumbers = (importFunction)GetProcAddress(hinstLib, MyFunction");
//////////////////////////////////

With I try to use LoadLibrary(), hinstlib is NULL. If I try to use
LoadLibraryEx, hinstlib has a value, though addNumber is null.

Which means, I believe that I can load the dll, but cant load the methods.

Well, not really. It means you can read the DLL as a file.
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE just copies the bits into memory. It
doesn’t actually “load” the DLL, and you cannot call GetProcAddress on a
DLL loaded that way.

The reason you can’t load it is exactly what I said. A 64-bit process
cannot load a 32-bit DLL. You will have to build a 64-bit version of
your DLL.

By the way, never copy 32-bit DLLs into the System32 directory on a
64-bit system. 32-bit DLLs go in \Windows\SysWOW64. 64-bit DLLs go in
\Windows\System32.


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

Tom,

I will generate the 64-bit version of my DLL. But, what function I need to
use: LoadLibrary or LoadLibraryEx? Can you show me a example?

Thanks

On Tue, Aug 2, 2011 at 3:53 PM, Tim Roberts wrote:

> Silvio Silva wrote:
> >
> > It doesnt load.
> >
> > See code below:
> >
> > typedef double (*importFunction)();
> > …
> > HINSTANCE hinstLib =
> >
> LoadLibraryEx(TEXT(“C:\Windows\System32\GerarDLL.dll”),NULL,LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE);
> > …
> > importFunction addNumbers;
> > addNumbers = (importFunction)GetProcAddress(hinstLib, MyFunction");
> > //////////////////////////////////
> >
> > With I try to use LoadLibrary(), hinstlib is NULL. If I try to use
> > LoadLibraryEx, hinstlib has a value, though addNumber is null.
> >
> > Which means, I believe that I can load the dll, but cant load the
> methods.
>
> Well, not really. It means you can read the DLL as a file.
> LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE just copies the bits into memory. It
> doesn’t actually “load” the DLL, and you cannot call GetProcAddress on a
> DLL loaded that way.
>
> The reason you can’t load it is exactly what I said. A 64-bit process
> cannot load a 32-bit DLL. You will have to build a 64-bit version of
> your DLL.
>
> By the way, never copy 32-bit DLLs into the System32 directory on a
> 64-bit system. 32-bit DLLs go in \Windows\SysWOW64. 64-bit DLLs go in
> \Windows\System32.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> 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
>

Silvio Silva wrote:

Tom,

Tim.

I will generate the 64-bit version of my DLL. But, what function I
need to use: LoadLibrary or LoadLibraryEx? Can you show me a example?

It’s just an ordinary DLL, so a perfectly ordinary LoadLibrary will
work. There are a billion examples on the web.

typedef double __stdcall (*importFunction)();
HINSTANCE hDLL = LoadLibrary(TEXT(“GerarDLL.dll”));
importFunction addNumbers = GetProcAddress(hDLL, “MyFunction” );

You should specify __stdcall or __cdecl – whichever one you actually used.

However, if the DLL is required for the operation of your driver, you
can also use implicit loading, by providing a prototype and adding the
DLL’s import library to your library list.

extern double MyFunction();


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

While it is true that a 64-bit process can only load 64-bit DLLs, do we know
whether the OP is using a 32-bit process or a 64-bit process? All I’ve seen
is that the DLL is a 32-bit DLL, but nothing about the context in which it
is used.
joe

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Tuesday, August 02, 2011 3:25 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Implementing DLL in UMDF

xxxxx@gmail.com wrote:

Hi friends

I’m having the same problem.

What problem?

I tried to include de lib in SOUCES but it doesnt work.

It doesn’t BUILD or it doesn’t LOAD?

I generated my DLL using Visual C++ 2010, 32bits. But, I’m using Win7
64bits.

A 64-bit process can only load 64-bit DLLs.


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


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