Create a dll from a .h file

Hi

I hope i am posting in the correct place. I am developing a web based application in asp.net and am in the process of trying to integrate a third party application. The third party application is supplied in the form of a.h file.

The example they provided is also in C++, which uses the.h file in question. I would like to create adll from this.h file which i can then call from my .Net code. They have provided me with the following advice about creating a wrapper, which i must admit is a little beyond my current C++ understanding. I would be grateful if someone could explain the steps a little clearer to me or suggest a possible solution. I am currently developing in Visual Studio .Net 2003.

Notes about wrapping the Paper SDK for VS7/VS8:

- The Paper SDK lib\dll directory must be in your path.

- GAPATHOME must be properly set to the GAPAT directory installed by the FDT (or a copy of that directory).

- The Paper SDK cannot be linked to VC8 libraries; the VC6 linker must be employed. In other words, both the demo code AND the actual Paper SDK libraries themselves use template library functions which VC8 does not know about.

- I wrapped Paper SDK functionality in a VC6 DLL exposing it via primitive types (char *, int, etc) and then called that VC6 DLL from

VC8 C++ (mixing managed and unmanaged code). The VC8 C++ assembly is then easily referenced by/callable from .NET 2.0 C# or other managed code.

- Don't forget that memory allocated in a VC6 DLL must be freed by that DLL (cannot be freed by VC8 code). Your VC6 wrapper DLL has to expose a Delete function if it returns pointers to memory it has allocated.

- You can set GAPATHOME at runtime (using SetEnvironmentVariable) without having it already set in the environment if (and only if) you dynamically load the DLL that is linked to the Paper SDK components, using LoadLibrary and GetProcAddress. If the DLL's load when your code (app or DLL) is loaded, and then GAPATHOME is set afterwards, it is too late.

- A similar trick could be employed (with setcwd to set current

directory) to avoid having to have the Paper SDK lib\dll directory on your PATH.

Thanks in advance

Mike

[2336 byte] By [medders78] at [2007-12-22]
# 1

In general you cannot create a DLL from just a *.h file. The only case in which this would work would be if the *.h file contained all the function definitions in which case I question why it was a *.h file and not a *.cpp (or *.c) file.

I assume that the *.h file in question contains the declarations for the entry points to the Paper SDK DLL? Correct?

It looks from the description above that you need to create at least two wrappers. 1) a low-level wrapper written in Visual C++ 6.0 which exposes the Paper SDK via what look like very primitive types (and should probably be a C API) and 2) a further wrapper which then exposes this Visual C++ 6.0 DLL to the managed world - this higher level wrapper probably exposes the functionality via a set of C++/CLI classes.

As the author of these instructions states you need to ensure that memory is always allocated/freed in the same DLL.

The need for the first (low-level) wrapper seems slightly suspicious to me - but there may well be something going on that I am not aware of.

If the instructions are not clear then I would get in touch with the author as they certainly have much more context that I have.

JonathanCaves-MSFT at 2007-8-30 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2

Thanks for making that clearer.

Now that i have a better understanding i will try the author again.

medders78 at 2007-8-30 > top of Msdn Tech,Visual C++,Visual C++ General...