General information
Title:
Making API calls in C# which use structures?
I’m a FoxPro/VB programmer but new to C# and struggling with API calls. Any help would very much be appreciated. Does anyone have an example or experience of making similar API calls.
I’ve initialised the API:
[DllImport("User32.dll")]
static extern bool EnumDisplaySettings(long lpszDeviceName, long iModeNum, DEVMODE lpDevMode);
I’ve defined (and initialised) the required structure:
struct DEVMODE
{
public DEVMODE(string deviceName, string formName)
{
dmDeviceName = deviceName;
dmSpecVersion = 0;
dmDriverVersion = 0;
dmSize = 0;
dmDriverExtra = 0;
dmFields = 0;
dmOrientation = 0;
dmPaperSize = 0;
dmPaperLength = 0;
dmPaperWidth = 0;
dmScale = 0;
dmCopies = 0;
dmDefaultSource = 0;
dmPrintQuality = 0;
dmColor = 0;
dmDuplex = 0;
dmYResolution = 0;
dmTTOption = 0;
dmCollate = 0;
dmFormName = formName;
dmUnusedPadding = 0;
dmBitsPerPel = 0;
dmPelsWidth = 0;
dmPelsHeight = 0;
dmDisplayFlags = 0;
dmDisplayFrequency = 0;
}
string dmDeviceName;
int dmSpecVersion;
int dmDriverVersion;
int dmSize;
int dmDriverExtra;
long dmFields;
int dmOrientation;
int dmPaperSize;
int dmPaperLength;
int dmPaperWidth;
int dmScale;
int dmCopies;
int dmDefaultSource;
int dmPrintQuality;
int dmColor;
int dmDuplex;
int dmYResolution;
int dmTTOption;
int dmCollate;
string dmFormName;
int dmUnusedPadding;
int dmBitsPerPel;
long dmPelsWidth;
long dmPelsHeight;
long dmDisplayFlags;
long dmDisplayFrequency;
}
Finally I’ve made my call:
DEVMODE devMode = new DEVMODE(" "," ")
bool returnValue ;
returnValue = EnumDisplaySettings(0, 0, devMode);
The program builds but errors when attempting to execute the last line above with - “Object reference not set to an instance of an object”
Thanks,
Gary Drudge-Coates.
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only