- NSIS Discussion
- GetDeviceCaps Macro
Archive: GetDeviceCaps Macro
billym
29th December 2003 18:47 UTC
GetDeviceCaps Macro Help
can someone assist me with getting the bitdepth converted. I want the output to be in bits ex. 1, 2, 4, 8, 16, etc...
here is what I have so far.
!macro GetDeviceCaps devCap
System::Call "user32::GetDC(i $HWNDPARENT) i .s"
System::Call "gdi32::GetDeviceCaps(i s, i ${devCap}) i .r0"
StrCmp ${devCap} "BITSPIXEL" +1 +3
System::Call "kernel32::MulDiv??????????????
!macroEnd
!insertmacro GetDeviceCaps "BITSPIXEL"
Joel
30th December 2003 16:10 UTC
Just for the record, did you get the awnser?
Maybe I can help... :)
billym
30th December 2003 22:23 UTC
Actually no, but I did get it working partially. I have a macro that is almost complete for calling the getdevice cap api.
billym
31st December 2003 14:41 UTC
I am in the process of creating the plugin version of this as well but having a problem. Here is my function:
void __declspec(dllexport) nsGetDeviceCaps(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
{
char buf[1024];
popstring(buf);
EXDLL_INIT();
{
HWND winHandle = GetDesktopWindow();
HDC deviceContext = GetDC(winHandle);
int colorDepth = GetDeviceCaps(deviceContext, buf);
ltoa(colorDepth, buf, 10);
pushstring(buf);
}
}
This fails when I call it from the script like this:
nsAPIgdi::nsGetDeviceCaps BITSPIXEL
I have determined that the cause of the problem is when the parameter is passed to the function. In the case of this API call, the params that get passed are defined in a header file. "BITSPIXEL", when passed into the buffer does not get changed into the defined value before being handed off to the API call causing it to fail.
I am a DOTNET developer and learning C/C++ at the moment. Really enjoying nsis. I am starting with this plugin as the first of a framework of nsAPI plugins for the more advanced API's that are harder to call from the system plugin. I have intentions of working on suites of these plugins so that you can choose any number of these mini-plugins for your installer without bloating your install package.
If someone knows how to get the function to lookup the value of the parameter passed before the API is called it would really help.
Joel
31st December 2003 16:20 UTC
Yeah, it's the HWND hwndParent.
You'll need to use strings....
Use some of atoi or atof functions to convert a string to a decent integer or long integer.
There's a function in system plugin source named "myatoi".
billym
31st December 2003 18:39 UTC
If I try to do it this way I will need to build a reference table for all of the defines that already exist. I am looking for a way to make the API call to see my parameter as the define that windows provides for this API. I may be wrong. Could you please provide an example.
Joel
31st December 2003 19:45 UTC
Let me try one....
kichik
1st January 2004 17:25 UTC
You can't use defines in the plug-in. Defines are processed at compile time on the compiler side. You will have to convert the string into a number as Lobo suggested.
As for the System.dll code, as BITPIXEL was only defined when the macro was inserted, it wasn't defined when you actually called !insertmacro. That means that ${BITSPIXEL} was passed as ${BITSPIXEL} and not as 12.
billym
2nd January 2004 14:31 UTC
It seems to handle the conversion of ${BITSPIXEL} to the 12 fine in this example.
kichik
2nd January 2004 14:33 UTC
It handles the conversion once BITSPIXEL is actually defined. That only happens after the macro is inserted for the first time. You should define it outside of the macro so you can use it as a parameter for the macro without actually inserting the macro.
billym
2nd January 2004 15:25 UTC
So instead of just uncommenting the defines needed within the macro you would define the params in your script and never modify the macro?
kichik
2nd January 2004 15:26 UTC
You should define them above the macro definition but still in the header file. See Include\Sections.nsh for an example.