Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9154363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:24:58+00:00 2026-06-17T12:24:58+00:00

I have a c# application running on winCE 6.0 version. I need to unload/reload

  • 0

I have a c# application running on winCE 6.0 version. I need to unload/reload the SD card driver at run time. I am attempting to do this via calling FindFirstDevice, then DeactivateDevice/ActivateDeviceEX calls. My problem is the FindFirstDevice() call always fails. I believe it to be a problem with the way I am marshalling the second parameter to it. Can anyone tell me what I am doing wrong? Here is the code:

  [DllImport("coredll.dll", SetLastError = true)]
  public static extern int FindFirstDevice(DeviceSearchType
  searchType, IntPtr searchParam, ref DEVMGR_DEVICE_INFORMATION pdi);

  public bool MountSDCardDrive(string mRegPath)
  {
     const int INVALID_HANDLE_VALUE = -1;

     int handle = INVALID_HANDLE_VALUE;
     DeviceSearchType searchType = DeviceSearchType.DeviceSearchByDeviceName;

     DEVMGR_DEVICE_INFORMATION di = new DEVMGR_DEVICE_INFORMATION();
     di.dwSize = (uint)Marshal.SizeOf(typeof(DEVMGR_DEVICE_INFORMATION));

     string searchParamString = "*";
     IntPtr searchParam = Marshal.AllocHGlobal(searchParamString.Length);
     Marshal.StructureToPtr(searchParamString, searchParam, false);

     handle = FindFirstDevice(searchType, searchParam, ref di);
     if (handle == INVALID_HANDLE_VALUE)
     {
        // Failure - print error
        int hFindFirstDeviceError = Marshal.GetLastWin32Error();

        using (StreamWriter bw = new StreamWriter(File.Open(App.chipDebugFile, FileMode.Append)))
        {
           String iua = "DevDriverInterface: error from FindFirstDevice: " + hFindFirstDeviceError.ToString();
           bw.WriteLine(iua);
        }
        return false;
     }

... (rest of code)

If I change the line Marshal.StructureToPtr(searchParamString, searchParam, false); to searchParam = Marshal.StringToBSTR(searchParamString);“I end up with error 1168 (ERROR_NOT_FOUND) instead of 18 (no more files).

Note my intent is to use a searchParamString of “SDH1” when I get this working. I am currently using searchParamString of “*” in order to see something returned and rule out the particular string value.

Thanks for any help you can give – Lynn

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:24:59+00:00Added an answer on June 17, 2026 at 12:24 pm

    FindFirstDevice must be used together with FindNextDevice (it uses the handle returned by FindFirstDevice as its first argument and returns TRUE if another device has been found) because you have to iterate all the devices to find the good one… and in order to to this you have to compare szLegacyName values in your structure.

    Remove:

    IntPtr searchParam = Marshal.AllocHGlobal(searchParamString.Length);
    

    And use only:

    IntPtr searchParam = Marshal.StringToBSTR(searchParamString);
    

    As that method already provides to allocate necessary memory (remember to use Marshal.FreeBSTR() in a finally block to free that memory space after).

    Your structure should look like:

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] 
    public struct DEVMGR_DEVICE_INFORMATION 
    { 
        public UInt32 dwSize; 
        public IntPtr hDevice; 
        public IntPtr hParentDevice; 
    
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)] 
        public String szLegacyName; 
    
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 
        public String szDeviceKey; 
    
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 
        public String szDeviceName; 
    
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 
        public String szBusName; 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application running at a URL like this: http://myapp.mydomain.com/myapp I don’t want
Right now I have a Java application running WMI querying event logs, this is
I have logical application running where i need to store the var algorithmToApply=1 or
I have an application running on a JBoss server. We need update the application
I have an application running on multiple IIS servers that need to parse a
I have application running for hours in embedded Linux, when suddenly the OOM Killer
I have rails application running in linode server .Some guy is continuously spamming (writing
I have an application running in JBoss AS6. Authentication is working using the FORM
I have an application running on Websphere Application Server 6.0 and it crashes nearly
I have an application running under WebLogic that is using standard forms authentication. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.