Leo1906

Help with DllCall and custom Return Format

12 posts in this topic

#1 ·  Posted

I am currently experimenting with DLLCalls and was wondering how I can get a custom Dataformat back?

The call goes like this:

GDALDatasetH CPL_DLL CPL_STDCALL GDALOpenEx( const char* pszFilename,
                                             unsigned int nOpenFlags,
                                             const char* const* papszAllowedDrivers,
                                             const char* const* papszOpenOptions,
                                             const char* const* papszSiblingFiles )

This is taken out of the header file (c++) of the Dll.

So the return value is a GDALDataset. How can I save this returned value into a variable in Autoit so that I can access it later on in another function call?

I tried like this:

$struct = DllStructCreate("GDALDataset *poDS;")
$ret = DllCall($dll, DllStructGetPtr($struct), "GDALOpenEx", "char", "D:\Bundeslaender.shp", "int", "0x04", "char", "", "char", "", "char", "")

But this wont seem to work. Any suggestions?

 

Kind regards,
Leo1906

Share this post


Link to post
Share on other sites



#2 ·  Posted

Hello. It should be something like this.

 

Local $aRet=DllCall("myDll","ptr","GDALOpenEx","str",$pszFilename,"uint",$nOpenFlags,"str",$papszAllowedDrivers,"str",$papszOpenOptions,"str",$papszSiblingFiles)
Local $pGDALDatasetH=$aRet[0]

Saludos

Share this post


Link to post
Share on other sites

#3 ·  Posted

Ok, thanks for that :)

Another question: how do I pass a NULL argument? In C++ I call this function like this:

GDALOpenEx(shapefile, GDAL_OF_VECTOR, NULL, NULL, NULL);

So my DllCall is like this?

$ret = DllCall($dll, "ptr", "_GDALOpenEx@0", "str", "D:\\Bundeslaender.shp", "uint", "0x04", "str", "NULL", "str", "NULL", "str", "NULL")

or like this?

$ret = DllCall($dll, "ptr", "_GDALOpenEx@0", "str", "D:\\Bundeslaender.shp", "uint", "0x04", "str", "", "str", "", "str", "")

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

like this would be ok.

 

$ret = DllCall($dll, "ptr", "_GDALOpenEx@0", "str", "D:\\Bundeslaender.shp", "uint", 0x04, "str", NULL, "str", NULL, "str", NULL)

Edit

Saludos

Edited by Danyfirex
edit

Share this post


Link to post
Share on other sites

#5 ·  Posted

Thanks a lot for your help. It seems to work now :)

Another question related to this. In this DLL are some functions which aren't called by passing arguments.

For example:

int GDALDataset::GetLayerCount()

This is the function I want to call using the GDALDataset created in the step before. Return is an integer. In C++ the call is very simple as you may imagine:

int i = GDALDataset.GetLayerCount();

How can I call this function using Autoit?
This wont work, I think maybe because the function is not expecting some arguments?

$ret = DllCall($dll, "int", "GetLayerCount", "ptr", $ret[0])

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

Hello. Just past nothing.

 

$ret = DllCall($dll, "int", "GetLayerCount")
$int=$ret[0]

Saludos

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ok, if I pass nothing than it takes the object created by previous DLLCall?

Another question. I think that the priour DLLCall is still not correct. This is how it's done in C++:

GDALDataset *poDS;
poDS = (GDALDataset*)GDALOpenEx(shapefile, GDAL_OF_VECTOR, NULL, NULL, NULL);

So, as you're executing the Open Command you cast the return to a pointer of the class? I don't know if I am saying it correctly.

Do you think that doing this call in Autoit would be this one here?:

$ret = DllCall($dll, "ptr", "GDALOpenEx", "str", "D:\Bundeslaender.shp", "uint", 0x04, "str", NULL, "str", NULL, "str", NULL)

 

Edited by Leo1906

Share this post


Link to post
Share on other sites

#8 ·  Posted

You will get return depends of the return type you use in the return parameter.

 

You will get a ptr in that call. I'm no sure about the casting you will need to do because I dont know what lib are you using. Please share the documentation.

 

 

Saludos

 

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

I'm using GDAL:

http://www.gdal.org/classGDALDataset.html#a9cb8585d0b3c16726b08e25bcc94274a

in the current up-to-date version.
I was using this in C++ a few times but now I want to learn more about Autoit and DLLCall's and thought that using this library could be a good way to start. Also when I learned enough I thought about maybe making a UDF to GDAL .. but thats somewhere far in the future :D

Share this post


Link to post
Share on other sites

#10 ·  Posted

You need to use the C version instead C++.

for getting  GDALDatasetH  the Opaque type used for the C bindings of the C++ GDALDataset class.

 

Saludos

Share this post


Link to post
Share on other sites

#11 ·  Posted

I don't really understand. So I need to download the C sourcecode and compile it to C DLL's or what?

Share this post


Link to post
Share on other sites

#12 ·  Posted

I really dont know. I need to check doc. I'll check later when I got some free time.

 

Saludos

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now