User Tag List

Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 27

Thread: Question about pointers to DOUBLEs (VC++6.0)

  1. #11
    No Products Registered

    Join Date
    Jul 2006
    Location
    Umeň, Sweden
    Posts
    1,090
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    This should work for pointing "pointer" to "argument"

    pointer = &argument;


    then if you need to read from the pointer

    double arg = *(double*)pointer;


    I'm not very good when it comes to pointers, but this should work, aight?

  2. #12
    Clicker Fusion 2.5 Developer

    Join Date
    May 2007
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    Hi, DanielRehn.

    Thanks for the advice but I can't pass a variable like "arg" in the function, only a pointer instead. The problem is, I can't change the way the function is called. What puzzles me is that it works with every other variable type.

  3. #13
    No Products Registered

    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    1,141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    Will the pointer always point to a double?

  4. #14
    No Products Registered

    Join Date
    Jul 2006
    Location
    Umeň, Sweden
    Posts
    1,090
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    Nono.. that's not what I meant...

    use this and pass pointer

    pointer = &argument;

  5. #15
    Clicker Fusion 2.5 Developer

    Join Date
    May 2007
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    Werbad: the pointer is originally a void pointer and then I change into the type using reinterpret_cast.

    Daniel: I tried that before.

    Maybe it's because of the size of the pointer from void* to DOUBLE* which is not correctly resized when I use reinterpret_cast?

  6. #16
    No Products Registered

    Join Date
    Jul 2006
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    A pointer is always the same size, 4 bytes, since it's just a memory address (sizeof(void*) == sizeof(double*)). And you can debug you extension as any application/dll, no difference, set breakpoints, step over/into code etc. From the help file:
    Quote Originally Posted by helpfile
    Open the Extensions \ Help \ Misc Documentation folder of the SDK and copy the file named "CopyRun.Bat" just beside MMF2.EXE in your MMF2 directory.
    If it does not already exist, create a "Temp" directory at the root of your C: drive. In this directory, create a "Rt" folder. Note: you can also edit CopyRun.bat and change the name of the directory. See below.
    Load your extension project file in Visual C++, open the Project Settings, display the "Debug" tab. In the line "Executable for debug session", enter the pathname to the file named "EdRt.exe" that you will find in the Data\Runtime folder of your MMF2 folder.
    In the "Program argument" line, enter "/fC:\Temp\Rt\App0.ccn".

    How to debug?

    Load MMF2, and create the application with the object that you want to debug.
    Hold down the SHIFT key while you click on the Run Frame or Run Application icon : this will instruct MMF2 to run the file "CopyRun.bat" so that the temporary files produced for the runtime are copied to the C:\Temp\Rt folder.
    Go into Visual C++, and press F5 to start the debugging : it will launch the runtime executable EdRt.exe with a command line indicating where to find the files to play. In this case, it will play App0.ccn found in the temporary folder on your C: drive, the file we just saved. Of course you can put breakpoints in your code.
    And I don't think the problem has anything to do with casting of pointers, it's something else that causes the problem.

  7. #17
    No Products Registered

    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    1,141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    I think you have misunderstood what reinterpret_cast actually does. There is no way of changing the type of any variable; Your variable pointer is initialized as a void* and will always be a void*.
    In your example you use this pointer and point it at the address of a double value, but it will still remain a void*, aka a typeless pointer. You get an error in your function because the compiler doesn't know how to handle pointer, since it has no type.
    I'm still curious why you use a void* and not simply a double*, since it will only be used for doubles.

  8. #18
    No Products Registered

    Join Date
    Jul 2006
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    What he's trying to do is a function that can take any type of object, and inside the function he somehow knows what object it is and casts it back to correct object pointer again. It's very common to use void pointers as parameters, since you then can pass anything.

    At least I hope that he in the function knows what he has sent in and dereferences it correctly, otherwise there will be problems.

    The compiler has no problems with void pointers, since all pointers are of the same size, the problem is if you cast it back to wrong type:

    void* pV = &iMyInt;
    double d = *(double*)pV; // Will access wrong memory due to different sizes of types.

    But int iMyNewInt = *(int*)pV; would work just fine.

  9. #19
    Clicker Fusion 2.5 Developer

    Join Date
    May 2007
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    Guys, your help is invaluable. I'll try that later when I'm at home. But I sense that debugging the code while the double is being passed to the function is something that will clear things up a lot. Thank you.

  10. #20
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jun 2006
    Posts
    6,773
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Question about pointers to DOUBLEs (VC++6.0)

    What he's trying to do is a function that can take any type of object, and inside the function he somehow knows what object it is and casts it back to correct object pointer again
    Perhaps he can use a template function in this situation? It depends on what he wants to do with the object I guess.

Page 2 of 3 FirstFirst 1 2 3 LastLast

Similar Threads

  1. An explanation of why I'm here, a few general pointers needed.
    By Tinez in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 26th January 2013, 05:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •