Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. problem to importing DLL files

problem to importing DLL files

Scheduled Pinned Locked Moved C#
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cppwxwidgetsss
    wrote on last edited by
    #1

    i have a form, i want to change the time and/or date of the system and now i have found the following code but it just generate errors i don't know what is exactly the problem it is not a run time error, it is a compilation error i am using C# in visual studio 2008 here is the error message :

    "Error 39 Attribute 'StructLayout' is not valid on this declaration type. It is only valid on 'class, struct' declarations. D:\visual studio projects\firstCSharp\firstCSharp\settings.cs 16 12 firstCSharp"

    here is the code

    public partial class settings : Form
    {
    [StructLayout(LayoutKind.Sequential)]
    [DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]

        private static extern bool SetSystemTime(ref MyDateTime st);
    
    
    
        \[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)\]
    
        private extern static void GetSystemTime(ref MyDateTime sysTime);
    

    please tell me how can i handle this error thank you everybody in Advance

    L 1 Reply Last reply
    0
    • C cppwxwidgetsss

      i have a form, i want to change the time and/or date of the system and now i have found the following code but it just generate errors i don't know what is exactly the problem it is not a run time error, it is a compilation error i am using C# in visual studio 2008 here is the error message :

      "Error 39 Attribute 'StructLayout' is not valid on this declaration type. It is only valid on 'class, struct' declarations. D:\visual studio projects\firstCSharp\firstCSharp\settings.cs 16 12 firstCSharp"

      here is the code

      public partial class settings : Form
      {
      [StructLayout(LayoutKind.Sequential)]
      [DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]

          private static extern bool SetSystemTime(ref MyDateTime st);
      
      
      
          \[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)\]
      
          private extern static void GetSystemTime(ref MyDateTime sysTime);
      

      please tell me how can i handle this error thank you everybody in Advance

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      cppwxwidgetsss wrote:

      Attribute 'StructLayout' is not valid on this declaration type

      Now how about this: a StructLayout tells something about the layout of a struct you define. Throw it away. BTW: an app should not mess around with the system settings, such as Regional Settings, current date/time, etc. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      P 1 Reply Last reply
      0
      • L Luc Pattyn

        cppwxwidgetsss wrote:

        Attribute 'StructLayout' is not valid on this declaration type

        Now how about this: a StructLayout tells something about the layout of a struct you define. Throw it away. BTW: an app should not mess around with the system settings, such as Regional Settings, current date/time, etc. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Luc Pattyn wrote:

        an app should not mess around with the system settings, such as Regional Settings, current date/time, etc.

        Hear hear!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups