Results 1 to 4 of 4

Thread: Error when importing system dll

  1. #1

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    Error when importing system dll

    I am receiving this error when trying to import a system dll.
    error CS0246: The type or namespace name 'sysimport' could not be found (are you missing a using directive or assembly reference?)
    here is my code the line with the error is in red.
    Code:
    // Calling out a Win32 API function 
    
    using System;
    using System.Runtime.InteropServices;
    
    class CH4_14
    {
    	[System.Runtime.InteropServices.StructLayoutAttribute
    			(LayoutKind.Sequential, CharSet=CharSet.Auto)]
    	public struct _SYSTEM_INFO
    	{
    		public int dw0emID;
    		public int dwPageSize;
    		public int lpMinimumApplicationAdress;
    		public int lpMaximumApplicationAddress;
    		public int dwActiveProcessorMask;
    		public int dwNumberOfProcessors;
    		public int dwProcessorType;
    		public int dwAllocationGranularity;
    		public short wProcessorLevel;
    		public short wProcessorRevision;
    	}
    	
    	[sysimport(dll="Kernel32.dll")]
    		unsafe private static extern void
    			GetSystemInfo([marshal(UnmanagedType.LPVoid)]uint* bufptr);
    			
    	public static unsafe void Main()
    	{
    		try
    		{
    			_SYSTEM_INFO si = new _SYSTEM_INFO();
    			GetSystemInfo((uint*)&si);
    			Console.WriteLine("Processor Type = {0}", si.dwProcessorType);
    			Console.WriteLine("Number of Processors = {0}", si.dwNumberOfProcessors);
    			Console.WriteLine("Processor Level = {0}", si.wProcessorLevel);
    			Console.WriteLine("Processor Revision = {0}", si.wProcessorRevision);
    		}
    		
    		catch(Exception e)
    		{
    			Console.WriteLine("Exception Caught! {0}", e);
    		}
    	}
    }
    Last edited by Memnoch1207; Aug 14th, 2003 at 04:19 PM.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  2. #2

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    well I figured that error out...It's DLLImport("Kernel32.dll").

    but now I am getting a new error on this line

    error is "namespace 'marshal' can't be found."
    Code:
    GetSystemInfo([marshal(UnmanagedType.LPVoid)]uint* bufptr);
    which I really don't understand..considering the marshal class is located under the System.Runtime.InteropServices namespace.
    Last edited by Memnoch1207; Aug 14th, 2003 at 04:14 PM.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Well , dll in C# really sucks . What I do usually is : try to get it in C# first , if that was hard , then I put that dll and VB.NET class and export the dll , and use it within C# proj . Less time-consuming I believe .

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I think the m in marshall should be uppercase.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width