locked
Adding a DLL Reference to a win32 Project Application w/Visual C++ Express RRS feed

  • Question

  • I'm writing a program with DirectX and I would like to access a DLL file that will contain functions for use in my project...my first question is:

    Should I be using a Static Library or Dynamic Link Library?

    -I need to write CALLBACK functions for my project, which library type is best?

    My next question...

    If I need a Dynamic Link Library how do I reference it in my project? I have already linked the import library file and the header files of the DLL project. When I run the DirectX project(dx.exe), I get the error: cannot find MathFuncs.dll...

    I've tried referencing the .dll in Properties->Common Properties->FrameWork and References, however, when I add the proper path to Additional reference search paths and select Add Reference, no project appears in the Add Reference window...


    • Edited by paulmcco Tuesday, February 14, 2012 7:53 PM
    Tuesday, February 14, 2012 7:50 PM

Answers

  • Well, since you are using the message pump to get this information then why not use WM_KEYDOWN/WM_KEYUP? If this isn't good enough, try keeping a track on if the key has been pressed. So a static/global/per window variable of type bool. When WM_INPUT is run, it checks to see if the key is being pressed, if it is then it checks this variable to see if it is true or false. If it is false then this means that either the key hasn't been pressed prior to this (the variable is initialised to false) or the last keyboard event was the key being released. So if the key is being pressed and it wasn't in the pressed state prior to this then you run the TransitionFunc.

    You would then have to detect when the key is being released so you can update the variable to reflect this. This should restrict it enough so that only the initial press causes the transition, the user would then have to release the key and press it again to cause another transition.

    For a better place to ask specific questions about DirectX, try the DirectX Community forums. While people here can answer questions on VC itself and some WinAPI related questions, this isn't really the place for DirectX related questions. You will most likely have better responses there.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Marked as answer by paulmcco Tuesday, February 14, 2012 9:16 PM
    Tuesday, February 14, 2012 9:05 PM

All replies

  • For CALLBACK functions, why do you need them? The majority of the callback functions I write end up in my application's main executable. So I would say neither. But at the same time, as long as the function calling the callback can access the function address, then both are just as acceptable.You have to be more specific about what you are trying to do for anyone to give you more help.

    For your second question, this error has nothing to do with the linking. When Windows loads a process it starts looking through the list of DLLs that it is linked against and tries to load them. This error means that Windows just can't find the file MathFuncs.dll. To fix it, copy this DLL into the same directory as the executable file. Simple.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Tuesday, February 14, 2012 7:56 PM
  • I copied the .dll into the .exe directory that works fine I was trying to keep from having to copy the .dll everytime I update it...

    I am writing callbacks because I need to handle animation set blending and transition...I know D3DX has a method of doing this but I need more control...the problem I'm having now is that I want to transition between animation sets without being restricted by the continuous calls to "Update", a function within my main DirectX project.

    The reason being, I need two animations(primary and secondary) to run along two tracks(t1, and t2)... the main project has a trackPointer that points at t1 until "transition" is called, then as "transitionTime" increases, the trackPointer points to a scaled combination of t1 and t2 until it reaches t2...secondary animation becomes primary animation.

    also, the callback function itself would be in the main program...the DLL function would have a pointer to the callback...




    • Edited by paulmcco Tuesday, February 14, 2012 8:21 PM
    Tuesday, February 14, 2012 8:14 PM
  • Well, for dealing with the DLL, just setting the path for the debugger should be enough. So for the project that relates to the executable, go to Project Properties->Configuration Properties->Debugging and under Environment set it to PATH=c:\path\to\dll;%path% and make sure that Merge Environment is set to yes. (Obviously replacing c:\path\to\dll with the actual path to the DLL).

    Anyway, the callback function being located in a static library, DLL or even the executable won't make much of a difference to this problem. The static library callback will get merged with the executable anyway so it will end up in the executable regardless. Putting the callback function in the DLL will only really change the location of the function itself, it can still access everything in the processes address space the same as if it was in the executable itself. I think the only major difference though is that the DLL will allow you not have to link against the DLL so you can use LoadLibrary/GetProcAddress to get this function.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Tuesday, February 14, 2012 8:32 PM
  • the reason I ask is because I want to handle the event of a keyDown and regardless of the contiued keyDown, I would like to transition between animations...can you recommend a method?

    I'm using RAWINPUT, when a key is pressed a BOOL keyDown becomes true, once true and only once after becoming true, the animation is to transition between tracks...how do I limit the calls to "TransitionFunc" so that the animation transitions without interuption?

    For example, I have an 'idel' animation and a 'walk' animation...when the key 'W' is pressed the program is to transtion between 'idle' and 'walk'. the user may continually press the button 'W' so that the character moves forward, but I don't want the animation to transition over and over...


    • Edited by paulmcco Tuesday, February 14, 2012 8:53 PM
    Tuesday, February 14, 2012 8:38 PM
  • Well, since you are using the message pump to get this information then why not use WM_KEYDOWN/WM_KEYUP? If this isn't good enough, try keeping a track on if the key has been pressed. So a static/global/per window variable of type bool. When WM_INPUT is run, it checks to see if the key is being pressed, if it is then it checks this variable to see if it is true or false. If it is false then this means that either the key hasn't been pressed prior to this (the variable is initialised to false) or the last keyboard event was the key being released. So if the key is being pressed and it wasn't in the pressed state prior to this then you run the TransitionFunc.

    You would then have to detect when the key is being released so you can update the variable to reflect this. This should restrict it enough so that only the initial press causes the transition, the user would then have to release the key and press it again to cause another transition.

    For a better place to ask specific questions about DirectX, try the DirectX Community forums. While people here can answer questions on VC itself and some WinAPI related questions, this isn't really the place for DirectX related questions. You will most likely have better responses there.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Marked as answer by paulmcco Tuesday, February 14, 2012 9:16 PM
    Tuesday, February 14, 2012 9:05 PM
  • thank you
    Tuesday, February 14, 2012 9:13 PM