How to get a parameter while program is running?

  • Thread starter Thread starter Felix Joachim
  • Start date Start date
F

Felix Joachim

Hi,

is there a simple way to get the parameter a program is called with while
it's already running?

bye,
felix
 
If you mean command line arguments, you can call GetCommandLine().


http://msdn.microsoft.com/library/d...us/wcecoreos5/html/wce50lrfGetCommandLine.asp

--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
I tried importing GetCommandLine() like this:
[DllImport("Coredll.lib", CharSet=CharSet.Auto, SetLastError=true)]
static extern string GetCommandLine();

This returns void, even if there is an argument passed to the main function
in .Net.
Do I have to marshal the return value somehow?
 
I've changed the import to coredll.dll now.
[DllImport("coredll.dll", CharSet=CharSet.Auto, SetLastError=true)]

While calling the function I get a System.NotSupportedException.


Felix said:
I tried importing GetCommandLine() like this:
[DllImport("Coredll.lib", CharSet=CharSet.Auto, SetLastError=true)]
static extern string GetCommandLine();

This returns void, even if there is an argument passed to the main
function in .Net.
Do I have to marshal the return value somehow?

If you mean command line arguments, you can call GetCommandLine().


http://msdn.microsoft.com/library/d...us/wcecoreos5/html/wce50lrfGetCommandLine.asp
 
The Marshaler doesn't support returning strings from the P/Invoke. Try to use
IntPtr instead and then use Marshal.PtrToStringUni to get the string.

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


Felix Joachim said:
I've changed the import to coredll.dll now.
[DllImport("coredll.dll", CharSet=CharSet.Auto, SetLastError=true)]

While calling the function I get a System.NotSupportedException.


Felix said:
I tried importing GetCommandLine() like this:
[DllImport("Coredll.lib", CharSet=CharSet.Auto, SetLastError=true)]
static extern string GetCommandLine();

This returns void, even if there is an argument passed to the main
function in .Net.
Do I have to marshal the return value somehow?

If you mean command line arguments, you can call GetCommandLine().


http://msdn.microsoft.com/library/d...us/wcecoreos5/html/wce50lrfGetCommandLine.asp
 
Hi,

does anybody have some advice in this regard?
Maybe the function has to be imported in a different way?

Felix said:
I've changed the import to coredll.dll now.
[DllImport("coredll.dll", CharSet=CharSet.Auto, SetLastError=true)]

While calling the function I get a System.NotSupportedException.


Felix said:
I tried importing GetCommandLine() like this:
[DllImport("Coredll.lib", CharSet=CharSet.Auto, SetLastError=true)]
static extern string GetCommandLine();

This returns void, even if there is an argument passed to the main
function in .Net.
Do I have to marshal the return value somehow?

If you mean command line arguments, you can call GetCommandLine().


http://msdn.microsoft.com/library/d...us/wcecoreos5/html/wce50lrfGetCommandLine.asp
 
Alex already gave you the right answer:

[DllImport("coredll.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern IntPtr GetCommandLine();

//sample call
{
string args = Marshal.PtrToStringUni(GetCommandLine())
}

my return is args[] + " //i". Dont know if it will happen on your app too
since my ROM is a test buildso the extra " //i" might be a bug. Just ignore
it if you see the bastard.

Minh

Felix Joachim said:
Hi,

does anybody have some advice in this regard?
Maybe the function has to be imported in a different way?

Felix said:
I've changed the import to coredll.dll now.
[DllImport("coredll.dll", CharSet=CharSet.Auto, SetLastError=true)]

While calling the function I get a System.NotSupportedException.


Felix said:
I tried importing GetCommandLine() like this:
[DllImport("Coredll.lib", CharSet=CharSet.Auto, SetLastError=true)]
static extern string GetCommandLine();

This returns void, even if there is an argument passed to the main
function in .Net.
Do I have to marshal the return value somehow?


Ilya Tumanov [MS] wrote:
If you mean command line arguments, you can call GetCommandLine().


http://msdn.microsoft.com/library/d...us/wcecoreos5/html/wce50lrfGetCommandLine.asp
 
Alex already gave you the right answer:

[DllImport("coredll.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern IntPtr GetCommandLine();

//sample call
{
string args = Marshal.PtrToStringUni(GetCommandLine())
}

my return is args[] + " //i". Dont know if it will happen on your app too
since my ROM is a test buildso the extra " //i" might be a bug. Just ignore
it if you see the bastard.

Minh

Felix Joachim said:
Hi,

does anybody have some advice in this regard?
Maybe the function has to be imported in a different way?

Felix said:
I've changed the import to coredll.dll now.
[DllImport("coredll.dll", CharSet=CharSet.Auto, SetLastError=true)]

While calling the function I get a System.NotSupportedException.


Felix said:
I tried importing GetCommandLine() like this:
[DllImport("Coredll.lib", CharSet=CharSet.Auto, SetLastError=true)]
static extern string GetCommandLine();

This returns void, even if there is an argument passed to the main
function in .Net.
Do I have to marshal the return value somehow?


Ilya Tumanov [MS] wrote:
If you mean command line arguments, you can call GetCommandLine().


http://msdn.microsoft.com/library/d...us/wcecoreos5/html/wce50lrfGetCommandLine.asp
 
Back
Top