it appears to work with the example I posted below!

hmmm did you recreate the struct after changing the value (thus creating the struct from the pointer again) ?

I just saw that changing the finalbit variable is a bad idea, because it keeps crashing the engine, probably because of what's written in the sdk_engine\atypes.h file :
Code:
typedef struct BMAP {
...
void	*finalbits;	// bitmap content when locked, otherwise NULL
}


thus it seems that the value shouldn't be changed by the user, because the user can't unlock the bitmap that way...

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AcknexWrapper;

namespace eventExample
{
    using AcknexWrapper.Native;
    using System.Runtime.InteropServices;

    public static class FinalBit
    {
        public static IntPtr GetFinalBit(BMAP toGetFinalBitOf)
        {
            NativeBMAP nativeBmapStruct =
                (NativeBMAP)Marshal.PtrToStructure(
                    toGetFinalBitOf.getIntPtr(),
                    typeof(NativeBMAP));

            return
                nativeBmapStruct.finalbits;
        }

        public static void SetFinalBit(BMAP toSetFinalBitOf, IntPtr valueToSet)
        {
            IntPtr positionOfFinalBitsInStruct =
              Marshal.OffsetOf(typeof(NativeBMAP), "finalbits");

            // destination to write to = the pointer to the struct in unmanaged memory + the offset of the finalbits variable in the struct
            IntPtr positionToWriteTo =
              (IntPtr)(
                (int)toSetFinalBitOf.getIntPtr() +
                (int)positionOfFinalBitsInStruct);

            // write the new value to the position in the memory where the finalbit part of the
            // struct is stored
            Marshal.WriteIntPtr(
                positionToWriteTo,
                valueToSet);
        }
    }


    class Program
    { 
        //the main method, called by the scheduler
        private static IEnumerable<ScheduleMethod> myMainMethod()
        {
            // limit frame rate
            EngVar.fps_max = 60;

            // load an empty level
            EngFun.level_load(null);

            BMAP bla =
                BMAP.bmap_createblack(300, 300, 32);

            // print current value
            Console.WriteLine(FinalBit.GetFinalBit(bla));

            // change the finalbit value
            FinalBit.SetFinalBit(bla, (IntPtr)12345);

            // print current value
            Console.WriteLine(FinalBit.GetFinalBit(bla));

            yield return ScheduleMethod.wait(1);
        }

        static void Main(string[] args)
        {
            //open the engine
            EngFun.engine_open(null, null);

            //start the scheduler
            Scheduler.StartScheduler(myMainMethod);
        }
    }
}



Last edited by Stromausfall; 02/22/12 13:28.

get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread