title: Is it safe to pass function pointers as arguments to dll functions and invoke them from inside of the dll?
body: <p>I would like to pass some (dll or not) function pointers as arguments to some dll functions and call them from inside of the dll. I wonder if it is safe because I have found an information on <a href="http://publib.boulder.ibm.com/infocenter/zos/v1r10/index.jsp?topic=/com.ibm.zos.r10.cbcpx01/fpref.htm" rel="noreferrer">http://publib.boulder.ibm.com/infocenter/zos/v1r10/index.jsp?topic=/com.ibm.zos.r10.cbcpx01/fpref.htm</a> that:</p>
  
  <p><em>In DLL code, it is assumed that a function pointer points to a function descriptor. A function pointer call is made by first obtaining the function address through dereferencing the pointer; and then, branching to the function entry. When a non-DLL function pointer is passed to DLL code, it points directly to the function entry. An attempt to dereference through such a pointer produces an undefined function address. The subsequent branching to the undefined address may result in an exception.</em></p>
  
  <p>Does this rule apply to Visual Studio and other compilers as well?</p>
  
  <p>What precisely I am trying to do is to solve the problem of memory allocation and deallocation between various dll and non-dll functions. My idea is to pass two function pointers - for common allocation and deallocation functions - to every dll in some initialization (e.g. Initialize(&amp;malloc, &amp;free)) and then do all memory management using these common and thus always compatible functions.</p>