-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DLL library cannot be called in VB VB or C# #2
Comments
using System;
using System.Runtime.InteropServices;
namespace PXDriveTester.Component
{
class CDIEmbedded
{
public enum InterfaceType
{
InterfaceTypeUnknown = 0,
InterfaceTypePata,
InterfaceTypeSata,
InterfaceTypeUsb,
InterfaceTypeIeee1394,
// INTERFACE_TYPE_UASP,
InterfaceTypeScsi,
InterfaceTypeNvme,
// INTERFACE_TYPE_USB_NVME,
};
public struct SmartAttribute
{
public byte Id;
public int StatusFlags;
public byte CurrentValue;
public byte WorstValue;
public long RawValue;
public byte Reserved;
}
[StructLayout(LayoutKind.Sequential)]
public struct RawSmart
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public byte[] raw;
}
[DllImport("cdie.dll")]
public static extern IntPtr CreateAtaSmart();
[DllImport("cdie.dll")]
public static extern void DestroyAtaSmart(IntPtr a);
[DllImport("cdie.dll")]
public static extern void InitAtaSmart(IntPtr a, bool useWmi, bool advancedDiskSearch, bool flagChangeDisk,
bool workaroundHD204UI, bool workaroundAdataSsd, bool flagHideNoSmartDisk);
[DllImport("cdie.dll")]
public static extern int GetDiskCount(IntPtr a);
[DllImport("cdie.dll")]
public static extern int GetPhysicalDriveId(IntPtr a, int index);
[DllImport("cdie.dll")]
[return: MarshalAs(UnmanagedType.LPStr)]
public static extern string GetModel(IntPtr a, int index);
[DllImport("cdie.dll")]
[return: MarshalAs(UnmanagedType.LPStr)]
public static extern string GetSerialNumber(IntPtr a, int index);
[DllImport("cdie.dll")]
[return: MarshalAs(UnmanagedType.LPStr)]
public static extern string GetFirmware(IntPtr a, int index);
[DllImport("cdie.dll")]
public static extern IntPtr GetSmart(IntPtr a, int index);
[DllImport("cdie.dll")]
public static extern int GetInterfaceType(IntPtr a, int index);
[DllImport("cdie.dll")]
public static extern uint GetTotalDiskSize(IntPtr a, int index);
[DllImport("cdie.dll")]
public static extern bool CreateRandomFile(string path, int size);
public static SmartAttribute[] ReadSmart(IntPtr a, int index)
{
var ptr = GetSmart(a, index);
var smart = new SmartAttribute[30];
for (var i = 0; i < 30; i++)
{
var raw = Marshal.PtrToStructure<RawSmart>(ptr);
smart[i].Id = raw.raw[0];
smart[i].StatusFlags = raw.raw[2] << 8 + raw.raw[1];
smart[i].CurrentValue = raw.raw[3];
smart[i].WorstValue = raw.raw[4];
smart[i].RawValue = RawValueToLong(raw.raw);
smart[i].Reserved = raw.raw[11];
ptr += 12;
}
return smart;
}
private static long RawValueToLong(byte[] buf)
{
return (Convert.ToInt64(buf[10] & 0xff) << 40) +
(Convert.ToInt64(buf[9] & 0xff) << 32) +
((buf[8] & 0xff) << 24) +
((buf[7] & 0xff) << 16) +
((buf[6] & 0xff) << 8) +
(buf[5] & 0xff);
}
}
} |
Thank you for your answer! The CDIEmbedded class has been created. How can I call it in the window? in VC++: CAtaSmart m_ATA{}; in C# : |
class CDIEmbedded C# code in Windows11 report errors : External component exception |
VB.NET 2017
|
Deepens the learning and application of pointer parameters VC++: VB.NET: C#: |
Save the following content as APP.exe.manifest. APP.exe.manifest: < ?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
you should export the functions as I do. cdelspec or stdcall depends on your application |
DLL library cannot be called in VB or C#,
The DLL library version has been V8.17.14,
How to modify to__ Stdcall, and call demo program
The text was updated successfully, but these errors were encountered: