Hello Everyone,
I created a project Under Win 32 and even tried MFC dll to use in other code....I have a C# code, when I try to add that .dll as a refrence that its not a valid assembly nor COM....How can I create a dlll to use under my C# project...
Thanks,
Harsimrat

How to Create a .dll to be used in other Projects
Faketone
Awesome....Really appreciate...I have a question which is all related...thats where it all started from....
BBDEVMGRLib is an .exe which I add as a refrence......It adds fine no problem.....they gave a C++ Code with it....which is done as you have done above but is not managed code....
enum
{ READ_EVENT, CLOSE_EVENT, NUM_EVENTS};class
USBClient: public IChannelEvents //implements the ICHannelEvents interface in order to receive notifications on the connection to the device{
public
:USBClient()
{
}
~USBClient()
{}
public :
int run()
{
//create some events for listening for notifications from the device
_events[READ_EVENT] = CreateEvent(NULL, FALSE, FALSE, NULL);
//unnamed_events[CLOSE_EVENT] = CreateEvent(NULL, TRUE, FALSE, NULL);
//unnamed if( _events[READ_EVENT] == INVALID_HANDLE_VALUE || _events[CLOSE_EVENT] == INVALID_HANDLE_VALUE ) { return false;}
public
: //implementation of the IChannelEvents interface virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void **ppvObject ){
if ( riid == IID_IChannelEvents || riid == IID_IUnknown) {*ppvObject = (IChannelEvents*)
this;AddRef();
return 0;}
return E_NOINTERFACE;}
virtual ULONG STDMETHODCALLTYPE AddRef(){
return ++_refcount;}
virtual ULONG STDMETHODCALLTYPE Release(){
ULONG count = --_refcount;
if ( count == 0 ){
delete this;}
return count;}
virtual HRESULT STDMETHODCALLTYPE raw_CheckClientStatus( void ){
return 0; //not implemented}
private
: //data membersIChannelPtr _channel;
ULONG _refcount;
HANDLE _events[NUM_EVENTS];
};
Then in the run code above we try to open channel, by passing these events...I was trying to do this code in C#.......I found no way to change this code in C#.......Do you have any ideas to do that.....
This is my first time working with USB....and managed code......
Thanks a lot......
Harsimrat
JoeyBlow
Ironically there is no documentation......only the code they provide with it.....
I can get you the code and .exe file or you can download from here....You can download the v4.1...
http://www.blackberry.net/products/software/desktop/
Then after installing ProgramFiles/Common/Research IN Motion/USB/
Alternatively my email address is (thukral.harsimrat at gmail.eraseme.com). I can send you the .exe file and related stuff...
I really appreciate for your help.....
Thanks a ton...
Harsimrat
Werdna1
This seems to be the source code to a thin COM wrapper of IChannelEvents (for some reason it is using the pimpl idiom to wrap IChannelPtr (comes from the #import directive). This is unmanaged C++ (not .NET).
Note that in C#, you program COM classes differently.
Inside the BBDEVMGRLib namespace, there should be COM classes you have to instantiate in C# before you can use its methods. The way to access those classes (in C#) should be something like:
BBDEVMGRLib.IChannelClass channel =
new BBDEVMGRLib.IChannelClass();
channel.CheckClientStatus();
But from your reply, it sounds like you lack knowledge on programming COM in C#. If this is so, you should start off programming some simpler COM classes (like the Office programming tutorials, or the shell).
Vinay Bhat MSFT
Sorry, that was pseudo code too
.
As I don't have the USB SDK you mentioned, I have no idea myself how to program BBDevMgrLib. If I had access to the tlb or exe that the vendor provides, I may be able to give you more suitable code. But right now, I don't what IChannelEvents, IChannel are, let alone give you decent code that describes them.
Is there an online document somewhere that describes what these interfaces are, and how to use them
Jenska
Kate E
Daniel Penalba
JMäkitalo
I hear you there , and I don't deny that fact, I was just working on some project which requires USB connection....
Thanks,
harsimrat
Moshfegh
PatrickR
Take a look at http://msdn2.microsoft.com/en-us/library/sd10k43k.aspx for interoperation and mixing native to managed code. One way, is to wrap your C++ code in managed wrappers and use the resulting managed binary in your C# application.
Also, take a look at http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=73716&SiteID=1 where you can find a simple example of using Managed VC++ code in C# applications.
Thanks, Ayman Shoukry VC++ TeamBrahim H
Hello Ayman,
I have code something like this...
#pragma
onceusing
namespace System;using
namespace BBDEVMGRLib;enum
{ READ_EVENT, CLOSE_EVENT, NUM_EVENT};namespace
USB{
__gc class USBClient: public IChannelEvents{
public:USBClient()
{
}
~USBClient()
{}
private:HANDLE client[NUM_EVENT];
};
}
It doesnt pick HANDLE......It tells me to give __gc or __nogc but when i do that...it has a problem....
I have done anything like this before...any help really appreciated....
Jean-Jacques Borie
As per the code above...
using BBDEVMGRLib;
then
public void USB()
{
IChannelEvents
channel = null;channel.CheckClientStatus();
}Then Error ...
Object reference not set to an instance of an object
I know there will be an error here....but I dont understand what it should refer too.....
Then I tried doing something....
IChannel _ch;
_ch = channel.CheckClientStatus();
Error 1 Cannot implicitly convert type 'void' to 'BBDEVMGRLib.IChannel'
Any ideas...Sorry for being a bugger.....
Rob Redford
Okay, but first, are you using VC++ 2003 or VC++ 2005
KoeiTG
In VC++2005 that would be
#pragma once
using namespace System;
using namespace BBDEVMGRLib;
namespace
USB{
enum { READ_EVENT, CLOSE_EVENT, NUM_EVENT};
ref class USBClient: public IChannelEvents
{
public:
USBClient() : client(gcnew cli::array<IntPtr>(NUM_EVENTS))
{
}
/// <summary>/// Example code you should use in C# (CAUTION: pseudocode only)...
/// usbClient.DoWorkWithNthHandle(CLOSE_EVENT);
/// </summary>
void DoWorkWithNthHandle(int n)
{
SignalHandle(this->client[ n ].ToPointer());
}
~USBClient()
{
}
private:
cli::array<IntPtr> ^client;
};
}