Hi,

quick question...
i am making a program without a form for windows ce and so i am trying to work in console but it seems some of the code cannot be implemented. does DllImport suppose to work in console?

Thx & BR
Ran.

Thanks.

Any idea why VS doesn't recognize the DllImport word?

i am using the next "using":
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Linq;
using System.Collections;
using System.Threading;

Post the code where you use it.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Runtime.InteropServices;

using System.Linq;
using System.Collections;
using System.Threading;

namespace RegConfig
{
    class Program
    {
        static void Main(string[] args)
        {
            RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"Init", true);
      
            reg.SetValue("Launch52", "\\Storage Card\\OpenIntApp\\OpenIntApp\\bin\\Release\\OpenIntApp.exe", RegistryValueKind.String);
            [DllImport("coredll.dll", EntryPoint = "RequestPowerNotifications")] // pre compile Error! - VS doesn't recognize DllImport
            
            

            Console.WriteLine("registry set");
        }
    }
}

Imports don't go inside methods. It should be inside the class, but not in the method. You are also missing the method signature. For example:

using System;
using System.Runtime.InteropServices;

class PlatformInvokeTest {
    [DllImport("msvcrt.dll")]
    public static extern int puts(string c);
    [DllImport("msvcrt.dll")]
    internal static extern int _flushall();

    public static void Main()     {
        puts("Test");
        _flushall();
    }
}

Edited 5 Years Ago by Momerath: n/a

I am trying to figure out how to flush the registry in windows ce but with no luck

after the code you see above i tried reg.Flush();, program compiled and run but registry is not presistant after boot
i now tried using RegFlushKey(reg); but 'reg' is not an IntPtr. the internet have solution like reg.data but i can't use it (pre-compile) error. MSDN is not helping

finaly i found the problem, i was using reg.flush(); but it didn't seem to work, the reason was that the windows ce emulator was set to clear all registry on soft reset also

This article has been dead for over six months. Start a new discussion instead.