Writing a C++ DLL in C#

D

Dan Diephouse

We are looking at a print driver by SoftCopy which allows can print to
images. The neat thing about it is that it has hooks which you can tie
into. It defines the hooks in C++ code though and I remail pretty
ignorant about using MS VC++.

They define a skeletal DLL like so:
(http://www.dobysoft.com/products/softcopy/help/index.htm?page=html/unattended/overview.html)

#include <windows.h>
#include "softcopy.h"

// Return job characteristics.
BOOL WINAPI scGetJobInfo(SCJOBINFO* info)
{
return FALSE;
}

// Return output filename and image type.
BOOL WINAPI scGetSaveFileName(SCFILEINFO* info)
{
lstrcpy(info->name, L"c:\\output\\test");
info->type = SC_PDF_MULTIPLE;
return TRUE;
}

// Display a message box when print job is completed.
void WINAPI scEndOfJob()
{
MessageBox(NULL, L"Printing done!", L"Alert",
MB_ICONINFORMATION | MB_OK | MB_SYSTEMMODAL | MB_SETFOREGROUND);
}

Now my question is - is it possible to implement this DLL in C#? Or do I
have to write the DLL in C++? I'm assuming that if the later, there's a
good way to call C# code?

I've seen lots of information on how to call c++ COM stuff from c#, but
I haven't seen a lot of information on going the other way around... Any
pointers to topics that I should look at whould be appreciated

Cheers,
- Dan
 
H

Hazz

I am sure I will be corrected but hopefully not for being dead wrong. You
can set a reference to this compenent in VSNET by going to the COM tab
rather than the .NET tab when you add this reference. That creates the proxy
automagically for you rather than getting at the metadata through command
line methods. -hazz
 
H

Hazz

Sorry I didn't read that correctly Dan.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callcomcomp.asphazz"Hazz" <[email protected]> wrote in messagenews:[email protected]...>I am sure I will be corrected but hopefully not for being dead wrong. Youcan set a reference to this compenent in VSNET by going to the COM tabrather than the .NET tab when you add this reference. That creates the proxyautomagically for you rather than getting at the metadata through commandline methods. -hazz>> "Dan Diephouse" <[email protected]> wrote in messagenews:[email protected]...>> We are looking at a print driver by SoftCopy which allows can print toimages. The neat thing about it is that it has hooks which you can tieinto. It defines the hooks in C++ code though and I remail pretty ignorantabout using MS VC++.>>>> They define a skeletal DLL like so:(http://www.dobysoft.com/products/softcopy/help/index.htm?page=html/unattended/overview.html)>>>> #include <windows.h>>> #include "softcopy.h">>>> // Return job characteristics.>> BOOL WINAPI scGetJobInfo(SCJOBINFO* info)>> {>> return FALSE;>> }>>>> // Return output filename and image type.>> BOOL WINAPI scGetSaveFileName(SCFILEINFO* info)>> {>> lstrcpy(info->name, L"c:\\output\\test");>> info->type = SC_PDF_MULTIPLE;>> return TRUE;>> }>>>> // Display a message box when print job is completed.>> void WINAPI scEndOfJob()>> {>> MessageBox(NULL, L"Printing done!", L"Alert",>> MB_ICONINFORMATION | MB_OK | MB_SYSTEMMODAL | MB_SETFOREGROUND);>> }>>>> Now my question is - is it possible to implement this DLL in C#? Or do Ihave to write the DLL in C++? I'm assuming that if the later, there's agood way to call C# code?>>>> I've seen lots of information on how to call c++ COM stuff from c#, but Ihaven't seen a lot of information on going the other way around... Anypointers to topics that I should look at whould be appreciated>>>> Cheers,>> - Dan>>
 
W

Willy Denoyette [MVP]

Dan Diephouse said:
We are looking at a print driver by SoftCopy which allows can print to
images. The neat thing about it is that it has hooks which you can tie
into. It defines the hooks in C++ code though and I remail pretty
ignorant about using MS VC++.

They define a skeletal DLL like so:
(http://www.dobysoft.com/products/softcopy/help/index.htm?page=html/unattended/overview.html)

#include <windows.h>
#include "softcopy.h"

// Return job characteristics.
BOOL WINAPI scGetJobInfo(SCJOBINFO* info)
{
return FALSE;
}

// Return output filename and image type.
BOOL WINAPI scGetSaveFileName(SCFILEINFO* info)
{
lstrcpy(info->name, L"c:\\output\\test");
info->type = SC_PDF_MULTIPLE;
return TRUE;
}

// Display a message box when print job is completed.
void WINAPI scEndOfJob()
{
MessageBox(NULL, L"Printing done!", L"Alert",
MB_ICONINFORMATION | MB_OK | MB_SYSTEMMODAL | MB_SETFOREGROUND);
}

Now my question is - is it possible to implement this DLL in C#? Or do I
have to write the DLL in C++? I'm assuming that if the later, there's a
good way to call C# code?

I've seen lots of information on how to call c++ COM stuff from c#, but I
haven't seen a lot of information on going the other way around... Any
pointers to topics that I should look at whould be appreciated

Cheers,
- Dan

Sorry, your only option is to use VC++.
SoftCopy loads the extentionby calling LoadLibrary and uses GetProcAddress
to get the exported functions like scGetJobInfo.
Both LoadLibrary and GetProcAddress cannot be used to load/call managed
code.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top