|
-
Aug 14th, 2003, 03:57 PM
#1
Thread Starter
Frenzied Member
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
-
Aug 14th, 2003, 04:06 PM
#2
Thread Starter
Frenzied Member
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
-
Aug 15th, 2003, 10:31 AM
#3
Sleep mode
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 .
-
Aug 15th, 2003, 03:50 PM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|