I get compiler error CS0212: "You can only take the address of an unfixed expression inside of a fixed statement initializer".
After looking at the MSDN article, I can not figure out how to implement a fixed statement in this context. If there is another way to do this, I'd love to hear it. Any help would be very appreciated!
The MSDN article can be found here.

Share on other sites

Original post by CodekaYou need a fixed pointer to deviceid, to guarantee that the GC won't move it around in memory while you're calling the P/Invoke. To do that, you can do something like this:

*** Source Snippet Removed ***

Note that while this "does" work, if that pointer is stored and used elsewhere in the unmanaged portion of the application at a later point in time it will result in problems (crashes, etc). Also, you don't NEED to do that at all for an output only parameter, just call it out, assuming that's all it does.

Description:This function allocates and ALP hardware system (board set) and returns an ALP handle so that it can be used by subsequence API functions. An error is reported if the requested device is not available or not ready.

In the associated header file, there is a

typedef unsigned long ALP_ID;

So I simply did the P/Invoke with DeviceIdPtr as a long. In other methods, the variable that DeviceIdPtr points to is called. For example:

Description:This function allocates and ALP hardware system (board set) and returns an ALP handle so that it can be used by subsequence API functions. An error is reported if the requested device is not available or not ready.

In the associated header file, there is a

typedef unsigned long ALP_ID;

So I simply did the P/Invoke with DeviceIdPtr as a long. In other methods, the variable that DeviceIdPtr points to is called. For example:

What is the most stable way of calling AlpDevAlloc, and then later using the value of DeviceId?

Again, thanks for your help!

It's operating on the same principle as OpenGL, where ALP_ID is a handle. As such you should be using an out parameter and an IntPtr, as demonstrated in my previous post. Also, you should identify what they mean by "long", although in the case of VS and GCC a long is generally 32 bits even in 64 bit mode, with long long being 64 bits. If the previous statement is true, then you should be using int, not long.

Where loadedArray is a byte[5,768,1024] I created by converting a series of black/white bitmaps into a 3-dimensional byte array (BitDepth = 1) . all long types in the API documentation have been replaced with int types. The code above compiles and runs, but AlpSeqPut returns a code that indicates an invalid parameter.

I know there can be problems with Marshalling arrays. Also, I'm still not 100% confident of my use of "out" in this context. So if these are the problem, I'd like to know here before I contact the developers of the API. Below is an excerpt from the documentation.

Edit: Mapped long parameters to IntPtr here. You'll have to check with the documentation to see whether they should be 32bits or 64bits on 64bit platforms (use int in the first case, IntPtr in the latter).

0

Share this post

Link to post

Share on other sites

This topic is 3189 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.