Hello All,

I'm trying to write an ATL COM to be used with an ASP on Windows CE
Environment.
I want to get the full path of an ASP file which calls the COM dll. In
my COM, I have a method called "MapPath" which is meant to return the
full path of an ASP file.

STDMETHODIMP CFile::MapPath(BSTR *strVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())

// TODO: Add your implementation code here
TCHAR filepath[MAX_PATH];
::GetModuleFileName (0, filepath, sizeof (filepath));

CComBSTR bstr (filepath);
*strVal = bstr.Detach();

return S_OK;
}

The ASP file instantiates the COM object and calls the method.

Set objFile = CreateObject ("Object.File")
==> Response.Write objFile.MapPath
Set objFile = Nothing

When the asp file invokes the method (indicated by an arrow) I expect
the method to return the full path of the ASP file
("\Windows\www\wwwpub\file\test.asp"). However, the MapPath method
returns "\Windows\services.exe".

I suppose there should be more lines of code to retrieve the caller's
full path but don't know what and how.

I'm very new to VC++. Could you post some code example here please?

Thank you very much,
Chan

Re: return full path of a caller (ASP) by Alex

Alex
Mon Jul 18 11:09:37 CDT 2005

That's because GetModuleFileName(0, ... ) returns the name of the calling
process' executable, and not the calling module's.
On XP and W2K3 try replacing the call to GetModuleFileName with

static int i = 0;
GetModuleHandleExGET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_UNCHANGED_REFCOUNT,
(LPCTSTR)&i, &hModule);

If you need this on W2K and NT4, you will need to use toolhelp library to
enumerate all modules for the current process and see if the address inside
your current module (like an address of a static variable above) falls
inside the memory range


--
Alex Feinman
---
Visit http://www.opennetcf.org
"Chan" <parkchan@hotmail.com> wrote in message
news:1121698195.039991.134360@z14g2000cwz.googlegroups.com...
> Hello All,
>
> I'm trying to write an ATL COM to be used with an ASP on Windows CE
> Environment.
> I want to get the full path of an ASP file which calls the COM dll. In
> my COM, I have a method called "MapPath" which is meant to return the
> full path of an ASP file.
>
> STDMETHODIMP CFile::MapPath(BSTR *strVal)
> {
> AFX_MANAGE_STATE(AfxGetStaticModuleState())
>
> // TODO: Add your implementation code here
> TCHAR filepath[MAX_PATH];
> ::GetModuleFileName (0, filepath, sizeof (filepath));
>
> CComBSTR bstr (filepath);
> *strVal = bstr.Detach();
>
> return S_OK;
> }
>
> The ASP file instantiates the COM object and calls the method.
>
> Set objFile = CreateObject ("Object.File")
> ==> Response.Write objFile.MapPath
> Set objFile = Nothing
>
> When the asp file invokes the method (indicated by an arrow) I expect
> the method to return the full path of the ASP file
> ("\Windows\www\wwwpub\file\test.asp"). However, the MapPath method
> returns "\Windows\services.exe".
>
> I suppose there should be more lines of code to retrieve the caller's
> full path but don't know what and how.
>
> I'm very new to VC++. Could you post some code example here please?
>
> Thank you very much,
> Chan
>


Re: return full path of a caller (ASP) by John

John
Mon Jul 18 12:35:03 CDT 2005

There's no way that the COM object can directly determine the ASP page that
is invoking into it. As far as the COM object you've written knows, it's
being called from a standard C++ executable and not from the ASP script
engine. So you'd need ASP itself to get the page information to the client.

I think you'd want something like below (note I haven't tried this myself so
I may not have it quite right)

Set urlPath = Request.Variables("SCRIPT_NAME"); ' this gets you virtual name
of ASP page
Set fileName = Server.MapPath(urlPath); ' this maps virtual name -> physical
name

--
John Spaith
Software Design Engineer, Windows CE
Microsoft Corporation

Check out the new CE Networking Team Blog at http://blogs.msdn.com/cenet/.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2003 Microsoft Corporation. All rights
reserved.

"Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
news:OSMBjL7iFHA.3256@TK2MSFTNGP12.phx.gbl...
> That's because GetModuleFileName(0, ... ) returns the name of the calling
> process' executable, and not the calling module's.
> On XP and W2K3 try replacing the call to GetModuleFileName with
>
> static int i = 0;
> GetModuleHandleExGET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_UNCHANGED_REFCOUNT,
> (LPCTSTR)&i, &hModule);
>
> If you need this on W2K and NT4, you will need to use toolhelp library to
> enumerate all modules for the current process and see if the address
> inside your current module (like an address of a static variable above)
> falls inside the memory range
>
>
> --
> Alex Feinman
> ---
> Visit http://www.opennetcf.org
> "Chan" <parkchan@hotmail.com> wrote in message
> news:1121698195.039991.134360@z14g2000cwz.googlegroups.com...
>> Hello All,
>>
>> I'm trying to write an ATL COM to be used with an ASP on Windows CE
>> Environment.
>> I want to get the full path of an ASP file which calls the COM dll. In
>> my COM, I have a method called "MapPath" which is meant to return the
>> full path of an ASP file.
>>
>> STDMETHODIMP CFile::MapPath(BSTR *strVal)
>> {
>> AFX_MANAGE_STATE(AfxGetStaticModuleState())
>>
>> // TODO: Add your implementation code here
>> TCHAR filepath[MAX_PATH];
>> ::GetModuleFileName (0, filepath, sizeof (filepath));
>>
>> CComBSTR bstr (filepath);
>> *strVal = bstr.Detach();
>>
>> return S_OK;
>> }
>>
>> The ASP file instantiates the COM object and calls the method.
>>
>> Set objFile = CreateObject ("Object.File")
>> ==> Response.Write objFile.MapPath
>> Set objFile = Nothing
>>
>> When the asp file invokes the method (indicated by an arrow) I expect
>> the method to return the full path of the ASP file
>> ("\Windows\www\wwwpub\file\test.asp"). However, the MapPath method
>> returns "\Windows\services.exe".
>>
>> I suppose there should be more lines of code to retrieve the caller's
>> full path but don't know what and how.
>>
>> I'm very new to VC++. Could you post some code example here please?
>>
>> Thank you very much,
>> Chan
>>
>



Re: return full path of a caller (ASP) by Alex

Alex
Mon Jul 18 17:58:50 CDT 2005

Oh, right... I somehow assumed (instead of reading the post, I guess) that
he wanted the dll path. Yes, of course it's
Server.MapPath(Request.ServerVariables("SCRIPT_NAME"))

--
Alex Feinman
---
Visit http://www.opennetcf.org
"John Spaith [MS]" <jspaith@ONLINE.microsoft.com> wrote in message
news:%23FkGJ87iFHA.3288@TK2MSFTNGP09.phx.gbl...
> There's no way that the COM object can directly determine the ASP page
> that is invoking into it. As far as the COM object you've written knows,
> it's being called from a standard C++ executable and not from the ASP
> script engine. So you'd need ASP itself to get the page information to
> the client.
>
> I think you'd want something like below (note I haven't tried this myself
> so I may not have it quite right)
>
> Set urlPath = Request.Variables("SCRIPT_NAME"); ' this gets you virtual
> name of ASP page
> Set fileName = Server.MapPath(urlPath); ' this maps virtual name ->
> physical name
>
> --
> John Spaith
> Software Design Engineer, Windows CE
> Microsoft Corporation
>
> Check out the new CE Networking Team Blog at http://blogs.msdn.com/cenet/.
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> You assume all risk for your use. © 2003 Microsoft Corporation. All rights
> reserved.
>
> "Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
> news:OSMBjL7iFHA.3256@TK2MSFTNGP12.phx.gbl...
>> That's because GetModuleFileName(0, ... ) returns the name of the calling
>> process' executable, and not the calling module's.
>> On XP and W2K3 try replacing the call to GetModuleFileName with
>>
>> static int i = 0;
>> GetModuleHandleExGET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_UNCHANGED_REFCOUNT,
>> (LPCTSTR)&i, &hModule);
>>
>> If you need this on W2K and NT4, you will need to use toolhelp library to
>> enumerate all modules for the current process and see if the address
>> inside your current module (like an address of a static variable above)
>> falls inside the memory range
>>
>>
>> --
>> Alex Feinman
>> ---
>> Visit http://www.opennetcf.org
>> "Chan" <parkchan@hotmail.com> wrote in message
>> news:1121698195.039991.134360@z14g2000cwz.googlegroups.com...
>>> Hello All,
>>>
>>> I'm trying to write an ATL COM to be used with an ASP on Windows CE
>>> Environment.
>>> I want to get the full path of an ASP file which calls the COM dll. In
>>> my COM, I have a method called "MapPath" which is meant to return the
>>> full path of an ASP file.
>>>
>>> STDMETHODIMP CFile::MapPath(BSTR *strVal)
>>> {
>>> AFX_MANAGE_STATE(AfxGetStaticModuleState())
>>>
>>> // TODO: Add your implementation code here
>>> TCHAR filepath[MAX_PATH];
>>> ::GetModuleFileName (0, filepath, sizeof (filepath));
>>>
>>> CComBSTR bstr (filepath);
>>> *strVal = bstr.Detach();
>>>
>>> return S_OK;
>>> }
>>>
>>> The ASP file instantiates the COM object and calls the method.
>>>
>>> Set objFile = CreateObject ("Object.File")
>>> ==> Response.Write objFile.MapPath
>>> Set objFile = Nothing
>>>
>>> When the asp file invokes the method (indicated by an arrow) I expect
>>> the method to return the full path of the ASP file
>>> ("\Windows\www\wwwpub\file\test.asp"). However, the MapPath method
>>> returns "\Windows\services.exe".
>>>
>>> I suppose there should be more lines of code to retrieve the caller's
>>> full path but don't know what and how.
>>>
>>> I'm very new to VC++. Could you post some code example here please?
>>>
>>> Thank you very much,
>>> Chan
>>>
>>
>
>


Re: return full path of a caller (ASP) by Chan

Chan
Wed Jul 20 21:01:39 CDT 2005

Hello,

I thought I'd deleted my original post here. I didn't know you have
replied.
I have created another thread with the same problem ^^; My fault, sorry
about that.

The reason why I need to find the full path of calling ASP is because
I'm creating a file system object in windows CE.
I want to access the object from ASP so I can create, copy, move and
delete files or folders. Those methods takes path parameters which are
absolute paths at the moment. I'd like to accept and process relative
paths as well. To do so, I need to find out the current path of the ASP
to start from there.

There is no file system object (Scripting.FileSystemObject) available
in Windows CE. That's why I'm creating one myself.

Thank you very much for your replies
Chan


Re: return full path of a caller (ASP) by Alex

Alex
Thu Jul 21 17:46:50 CDT 2005

It would be impossible to retrieve the ASP script path from the ActiveX
component created by the script. This kind of information simply is not
passed automatically to the component. The alternative for you is to pass
Request.ServerVariables("SCRIPT_PATH") to the ActiveX property or method.

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Chan" <parkchan@hotmail.com> wrote in message
news:1121911299.270538.29620@f14g2000cwb.googlegroups.com...
> Hello,
>
> I thought I'd deleted my original post here. I didn't know you have
> replied.
> I have created another thread with the same problem ^^; My fault, sorry
> about that.
>
> The reason why I need to find the full path of calling ASP is because
> I'm creating a file system object in windows CE.
> I want to access the object from ASP so I can create, copy, move and
> delete files or folders. Those methods takes path parameters which are
> absolute paths at the moment. I'd like to accept and process relative
> paths as well. To do so, I need to find out the current path of the ASP
> to start from there.
>
> There is no file system object (Scripting.FileSystemObject) available
> in Windows CE. That's why I'm creating one myself.
>
> Thank you very much for your replies
> Chan
>