Valhalla Legends Forums Archive | C/C++ Programming | Creating a DLL

AuthorMessageTime
Infamous
Hi, I've tried to convert this code into VB but failed  :'(

Now I need help putting this code into a DLL which I can use in my VB app.

I currently do not have a C++ compiler. Can someone put this code into a dll, which will allow me to call the code from my VB app? I'll give a working cd-key of your choice: WC2, WC3, or Starcraft.

Heres the code.

[code]
BitFields::BitFields(BYTE *d)
{
m_Data = d;
m_Pos = 0;
}

BitFields::BitFields()
{
m_Pos = 0;
}


DWORD BitFields::GetBitField( DWORD pos, DWORD len)
{
DWORD dBitField = (DWORD)(*(unsigned __int64 *)(m_Data+pos/8)<<(64-len-(pos&7))>>(64-len));
m_sDebugLines.AddTail( PrintBitField( pos, len, dBitField)) ;
return dBitField ;
}


DWORD BitFields::GetField(DWORD len, CString sDebug)
{
m_sDebugComment = sDebug ;
return GetBitField( (m_Pos+=len)-len, len) ;
}

//.h file

class BitFields
{
public:
BYTE* m_Data;
DWORD m_Pos;
CString m_sDebugComment ;
CStringList m_sDebugLines ;

BitFields(BYTE *d) ;
BitFields() ;

DWORD GetBitField( DWORD pos, DWORD len) ;
DWORD GetField( DWORD len, CString sDebug="-") ;

} ;

[/code]


Thanks.

November 10, 2005, 8:29 PM
Yoni
You can't instantiate exported C++ classes in VB.
November 10, 2005, 8:32 PM
Myndfyr
[quote author=Yoni link=topic=13194.msg133434#msg133434 date=1131654758]
You can't instantiate exported C++ classes in VB.
[/quote]

What about through COM?
November 10, 2005, 9:48 PM
Yoni
That is not a COM class.
November 10, 2005, 10:10 PM
Myndfyr
[quote author=Yoni link=topic=13194.msg133446#msg133446 date=1131660633]
That is not a COM class.
[/quote]

I was just speaking generally.
November 10, 2005, 10:42 PM
Yoni
You still don't instantiate the C++ class in VB. You just access a COM interface, and the DLL code instantiates the class, not the VB code.
November 11, 2005, 2:10 PM
Adron
[quote author=Yoni link=topic=13194.msg133434#msg133434 date=1131654758]
You can't instantiate exported C++ classes in VB.
[/quote]

Just give him a set of wrapper functions...

[code]
DWORD __stdcall CreateBitfields()
{
    return (DWORD)new Bitfields;
}

void __stdcall DestroyBitfields(DWORD handle)
{
    delete (Bitfields*)handle;
}

DWORD __stdcall GetBitField(DWORD handle, DWORD pos, DWORD len)
{
    return ((Bitfields*)handle)->GetBitField(pos, len);
}
[/code]

etc...
November 11, 2005, 7:45 PM

Search