AX Controls 
Author Message
 AX Controls

Is it standard behavior that the use of App.Path in an AX control returns
the path of the OCX (in this case Windows/System32/) instead of the path of
the exe file using the OCX ?

TIA,

Dans



Sat, 21 Jan 2012 03:13:57 GMT  
 AX Controls



Quote:
> Is it standard behavior that the use of App.Path in an AX
> control returns the path of the OCX (in this case
> Windows/System32/) instead of the path of
> the exe file using the OCX ?

Yes, and that's IMO a good thing.

If you want to determine the Path of the hosting Exe from within
a satellite-COMponent (where ever its binary is placed) - try:

Private Declare Function GetModuleFileNameA Lib "kernel32" _
    (ByVal hModule&,  ByVal lpFileName$, ByVal nSize$) As Long

  NameLen = 260
  FName = Space(NameLen )
  NameLen = GetModuleFileNameA(0, FName, NameLen )
  FName = Left$(FName, NameLen )

Olaf



Sat, 21 Jan 2012 04:07:28 GMT  
 AX Controls


Quote:


> Newsbeitrag

>> Is it standard behavior that the use of App.Path in an AX
>> control returns the path of the OCX (in this case
>> Windows/System32/) instead of the path of
>> the exe file using the OCX ?
> Yes, and that's IMO a good thing.

Good or bad, I just know I spent 4 hours trying to trace down an 'Invalid
Path' error, but now I know.

Quote:
> If you want to determine the Path of the hosting Exe from within
> a satellite-COMponent (where ever its binary is placed) - try:

> Private Declare Function GetModuleFileNameA Lib "kernel32" _
>     (ByVal hModule&,  ByVal lpFileName$, ByVal nSize$) As Long

>   NameLen = 260
>   FName = Space(NameLen )
>   NameLen = GetModuleFileNameA(0, FName, NameLen )
>   FName = Left$(FName, NameLen )

> Olaf

Thanks, I may use that.

Regards,

DanS



Sat, 21 Jan 2012 07:48:27 GMT  
 AX Controls


Quote:


> Newsbeitrag

>> Is it standard behavior that the use of App.Path in an AX
>> control returns the path of the OCX (in this case
>> Windows/System32/) instead of the path of
>> the exe file using the OCX ?
> Yes, and that's IMO a good thing.

> If you want to determine the Path of the hosting Exe from within
> a satellite-COMponent (where ever its binary is placed) - try:

> Private Declare Function GetModuleFileNameA Lib "kernel32" _
>    (ByVal hModule&,  ByVal lpFileName$, ByVal nSize$) As Long

>  NameLen = 260
>  FName = Space(NameLen )
>  NameLen = GetModuleFileNameA(0, FName, NameLen )
>  FName = Left$(FName, NameLen )

Your code gets the path for the current module, which is the AX. Here is the
one for the EXE:

Option Explicit

Private Declare Function GetModuleHandle Lib "kernel32" Alias _
    "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function GetModuleFileName Lib "kernel32" Alias _
    "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String,
_
    ByVal nSize As Long) As Long

Private Sub Form_Load()
    Debug.Print GetEXEPath()
End Sub

' Returns the EXE path without the trailing backslash "\"
Public Function GetEXEPath() As String
    Dim hModule As Long
    Dim sEXEFileName As String
    Dim ret As Long

    hModule = GetModuleHandle(vbNullString)
    sEXEFileName = String(2000, 0)
    ret = GetModuleFileName(hModule, sEXEFileName, 2000)
    ' Remove the extra nulls
    sEXEFileName = Mid(sEXEFileName, 1, InStr(sEXEFileName, Chr(0)) - 1)

    ' Get the path part
    GetEXEPath = Mid(sEXEFileName, 1, InStrRev(sEXEFileName, "\") - 1)
End Function



Sat, 21 Jan 2012 09:12:44 GMT  
 AX Controls



Quote:
> Your code gets the path for the current module,
> which is the AX.

Nope.

Please read, what the MSDN states, regarding the usage
of the first-param of GetModuleFileName() - and what
is returned, if it is left at Zero.

Aside from that, I've just tested the snippet again
(placed inside Class_Initialize of a small AX-Dll),
 compiled to - and placed in a different location
 than the hosting Exe - and what is shown is the
 Exe-Path, not the Dll-Path).

Nonetheless your Function does basically the same thing,
but more "explicitely", and it also already cuts off the
Exe-Filename from the returned "Full-ExePath".

Olaf



Sat, 21 Jan 2012 10:08:21 GMT  
 AX Controls


Quote:


> Newsbeitrag

>> Is it standard behavior that the use of App.Path in an AX
>> control returns the path of the OCX (in this case
>> Windows/System32/) instead of the path of
>> the exe file using the OCX ?
> Yes, and that's IMO a good thing.

> If you want to determine the Path of the hosting Exe from within
> a satellite-COMponent (where ever its binary is placed) - try:

> Private Declare Function GetModuleFileNameA Lib "kernel32" _
>     (ByVal hModule&,  ByVal lpFileName$, ByVal nSize$) As Long

>   NameLen = 260
>   FName = Space(NameLen )
>   NameLen = GetModuleFileNameA(0, FName, NameLen )
>   FName = Left$(FName, NameLen )

I've incorporated this into my AX control and it does work as expected.

(The OCX is installed to System32, but uses some files stored in a sub-
dir in the app dir. Without the above change, that sub-dir would have
needed to be created in System32 instead of the app dir, which I do not
want.)

Thanks again Olaf.

DanS



Sat, 21 Jan 2012 21:57:38 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Can't see properties for Ax control on userform

2. User AX Control

3. AX Control's Absolute Location in Access Form

4. User AX Control

5. Shape on top of a aX-control?

6. IE Warning RE AX Control

7. AX Controls Height and Width locked in IE?!

8. AX Control passing back?

9. Webbrowser Object in AX control

10. ax control hogs events in IE

11. Sizing an AX control to fit a frame

12. AX Controls Height and Width locked in IE?!

 

 
Powered by phpBB® Forum Software