locked
want to use .h header files in c# RRS feed

  • Question

  • Hi,

    I want to call the header files in my c# program.  Where i am using the acrobat sdk which has references to the header file. i tried prebuildevent where i did not have proper examples. 

    if anyone can through light on these it will be appreciated.

    thanks

    -rajashekar s

    Friday, July 21, 2006 6:28 AM

Answers

  • A C/C++ SDK for static linking is not suitable for developing C# programs.

    C#, by means of Interoperability Services, can at best access to exported functions of a DLL or to COM CoClass. Check if your SDK provides these capabilities.

    What you should do is to wrap your legacy code in exported functions or in COM CoClasses and invoke them trough InteropServices.

    In this way you could achieve the best level of adherence with your old implementation and save a lot of coding-time. I think this approach should be very productive.

    Prebuild event hasn't anything in common with C/C++ preprocessing, as I think you misunderstood. It's simply a way to give you a chance to perform some task before compiling the program.

    Friday, July 21, 2006 9:01 AM
  • hI,

    I had the same problem as you. I was on the need of using an API (Remedy) that was offered as a Win32 DLL. I had the DLL, the LIB and the header files. C# interop can consume Win32 static libraries but not dynamic ones.

    My solution:

    I have created a small Managed C++ DLL and I interact with my Win32 DLL from there. Is like building a wrapper.

    Regards

    Wednesday, July 26, 2006 11:17 PM

All replies

  • Header files (.h, .hpp) in C#?

    C# is not C, neither C++. The building process of C# doesn't require the existence of header files for modularization and exposition of public interface.

    You cannot use .h files in C#. At best, in case of a DLL with some export declarations, you can use it to declare signature-compatible P/Invoke function from whithin your C# class.

    What you mean?

    Friday, July 21, 2006 8:05 AM
  • hi,

    thanks for the email.  I have the requirement to convert all c++ programs to c# so i want to use the older version of acrobat sdk which uses the the header file with sdk dll's. in order to make  program to work i have to simulate exactly how it was done earlier i mean calling header file with the sdk.  i found some articles where they mention about calling 'prebuilderevent'  which will be compiled earlier than the regular program.

    if you can provide more information on 'prebuildevent' it should be ok or any other method.

    rajashekar s

     

    Friday, July 21, 2006 8:17 AM
  • A C/C++ SDK for static linking is not suitable for developing C# programs.

    C#, by means of Interoperability Services, can at best access to exported functions of a DLL or to COM CoClass. Check if your SDK provides these capabilities.

    What you should do is to wrap your legacy code in exported functions or in COM CoClasses and invoke them trough InteropServices.

    In this way you could achieve the best level of adherence with your old implementation and save a lot of coding-time. I think this approach should be very productive.

    Prebuild event hasn't anything in common with C/C++ preprocessing, as I think you misunderstood. It's simply a way to give you a chance to perform some task before compiling the program.

    Friday, July 21, 2006 9:01 AM
  • Here is a link to an exellent free book on interoperability.

    http://www.only4gurus.net/miscellaneous/comanddotnetinteroperability.pdf

    chapter 10 onwards shows how to use c++ com objects in c# .NET apps
    Friday, July 21, 2006 10:05 AM
  • I have used that sdk from Visual Foxpro with great success.

    I think the best way to use it in C#, however, it to define constants in a class rather than using them from a header file like the sdk gives you.

    You should be able to just copy them.  Alternatively, you can create enums for each item that would make your code more readable.

     

    HTH

    Friday, July 21, 2006 10:31 PM
  • hI,

    I had the same problem as you. I was on the need of using an API (Remedy) that was offered as a Win32 DLL. I had the DLL, the LIB and the header files. C# interop can consume Win32 static libraries but not dynamic ones.

    My solution:

    I have created a small Managed C++ DLL and I interact with my Win32 DLL from there. Is like building a wrapper.

    Regards

    Wednesday, July 26, 2006 11:17 PM