From: Bob Butler on

"Sarah M. Weinberger" <nospam_mweinberger(a)hotmail.com> wrote in message
news:B725B270-321F-4F80-B1B6-CDB40D7F76F8(a)microsoft.com...
<cut>
> Private Declare Function GetModuleFileName Lib "kernel32" Alias
> "GetModuleFileNameA" (ByVal hModule As Integer, ByVal lpFileName As
> String, ByVal nSize As Integer) As Integer

All of those Integers need to be Longs:

Private Declare Function GetModuleFileName Lib "kernel32" _
Alias "GetModuleFileNameA" (ByVal hModule As LONG, _
ByVal lpFileName As String, ByVal nSize As LONG) As LONG

If it's been working under XP then you've been lucky as the declaration is
wrong there as well. Most API documentation is for C and when that species
"int" it means a 32-bit integer which for VB is a Long.

> iLen = lLen

I don't see where you declare iLen in your code... you want that to be a
Long as well (or just drop it and use lLen)

> 'Get the module name.
> GetModuleFileName hModule, strModule, iLen

I suggest you always get the return value

Dim r As Long
r = GetModuleFileName(hModule, strModule, lLen)

In this case it's the number of characters returned which would let you do a
better test by checking that it is less than the buffer size and so you can
trunate the result in case you get any garbage after the valid data that
might contain VB6 and give you a false positive. Defensive coding is
frequently a great time saver.

Your code assumes that the result will always fit in 256 characters and that
it will never have anything after the terminating null character.


From: Sarah M. Weinberger on
Hi Bob! :-) and :-(

I feel dumb. I should crawl under a rock for not thinking of that.

That fixed the problem.

Thanks a lot for helping out!

Sarah
From: Nobody on
"Sarah M. Weinberger" <nospam_mweinberger(a)hotmail.com> wrote in message
news:B725B270-321F-4F80-B1B6-CDB40D7F76F8(a)microsoft.com...
> Private Function IsInIDE() As Boolean

Why don't you use this non-API version instead?

http://vbnet.mvps.org/code/core/isinide.htm


From: Ulrich Korndoerfer on
Hi,

Nobody schrieb:
> "Sarah M. Weinberger" <nospam_mweinberger(a)hotmail.com> wrote in message
> news:B725B270-321F-4F80-B1B6-CDB40D7F76F8(a)microsoft.com...
>> Private Function IsInIDE() As Boolean
>
> Why don't you use this non-API version instead?
>
> http://vbnet.mvps.org/code/core/isinide.htm

Because they differ in their result.

Eg if you have a compiled dll with the IsInIDE test and use that dll in
an application, if the application is run in the IDE the latter will
deliver False, the other True.

--
Ulrich Korndoerfer

VB tips, helpers, solutions -> http://www.proSource.de/Downloads/
From: Karl E. Peterson on
on 1/27/2010, Ulrich Korndoerfer supposed :
>>> Private Function IsInIDE() As Boolean
>>
>> Why don't you use this non-API version instead?
>>
>> http://vbnet.mvps.org/code/core/isinide.htm
>
> Because they differ in their result.
>
> Eg if you have a compiled dll with the IsInIDE test and use that dll in an
> application, if the application is run in the IDE the latter will deliver
> False, the other True.

That'd be pretty dumb, to ask a compiled component whether it's running
in the IDE, wouldn't it? Maybe I don't understand the objection.

--
..NET: It's About Trust!
http://vfred.mvps.org