2 registered members (TipmyPip, AndrewAMD),
1,151
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
What exactly is does "external only" mean referring to classes?
#365974
03/31/11 01:47
03/31/11 01:47
|
Joined: Aug 2004
Posts: 1,305 New York
PrenceOfDarkness
OP
Serious User
|
OP
Serious User
Joined: Aug 2004
Posts: 1,305
New York
|
The manual says that C++ classes can be used in lite-c but only external. What exactly does this mean? Does that mean I have to use a DLL to do so?
Man, the thought of using classes in lite-c just makes my mouth salivate O_O'.
"There is no problem that can't be solved with time and determination." -me prenceofdarkness for instant messages on AIM.
Looking for a model designer PLEASE, SEND ME A PRIVATE MESSAGE OR EMAIL IF YOU'RE INTERESTED.
|
|
|
Re: What exactly is does "external only" mean referring to classes?
[Re: PrenceOfDarkness]
#365977
03/31/11 06:19
03/31/11 06:19
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
yes, that means you can only use them with c++ plugins.
3333333333
|
|
|
Re: What exactly is does "external only" mean referring to classes?
[Re: Quad]
#365986
03/31/11 10:40
03/31/11 10:40
|
Joined: Aug 2004
Posts: 1,305 New York
PrenceOfDarkness
OP
Serious User
|
OP
Serious User
Joined: Aug 2004
Posts: 1,305
New York
|
still great news. just wanted to verify a bit more on this. i would just try it but i wont be home for a while. if i define an object via dll can i make instances of it in lite-c? if not can i make instances in the dll and use functions of the class in lite-c?
"There is no problem that can't be solved with time and determination." -me prenceofdarkness for instant messages on AIM.
Looking for a model designer PLEASE, SEND ME A PRIVATE MESSAGE OR EMAIL IF YOU'RE INTERESTED.
|
|
|
Re: What exactly is does "external only" mean referring to classes?
[Re: PrenceOfDarkness]
#365987
03/31/11 11:03
03/31/11 11:03
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
it basically works this way: you create an instance/object and return it's pointer to lite-c then wrap all functions of tat class in c++ as DLLFUNC s, make it so that it takes an instance pointer and necessary parameters, and calls that function over that instance with the given paramaters. all code below is psuedo-code: say, this is your class
class AwesomeClass{
private: int a, int b;
public AwesomeClass(int x,int y){
a = x; b = y;
}
public void setA(int newa){
a = newa;
}
public void setb(int newb){
b = newb;
}
public int sum(){
return a+b;
}
}
this is the wrapping in c++ part:
DLLFUNC AwesomeClass* ac_create(int a, int b){
return new AwesomeClass(a,b);
}
DLLFUNC void ac_setA(AwesomeClass* ac, int newa){
ac.setA(newa);
}
DLLFUNC void ac_setB(AwesomeClass* ac, int newB){
ac.setB(newB);
}
DLLFUNC int ac_sum(AwesomeClass* ac){
return ac.sum();
}
this is how you use it in lite-c first your Lite-c header, you may want to call it awesomeclass.h:
#define AwesomeClass int
AwesomeClass* ac_create(int a, int b);
void ac_setA(AwesomeClass* ac, int newa);
void ac_setB(AwesomeClass* ac, int newB);
int ac_sum(AwesomeClass* ac);
and then use it in lite-c:
AwesomeClass* myinstance = ac_create(3,5);
AwesomeClass* anotherinstance = ac_create(10,11);//you can create as many instances as you want
printf("%d",ac_sum(myinstance));//will show you 8
ac_setA(myinstance,5);
printf("%d",ac_sum(myinstance));//will show you 10
Last edited by Quadraxas; 03/31/11 11:04.
3333333333
|
|
|
Re: What exactly is does "external only" mean referring to classes?
[Re: PrenceOfDarkness]
#365988
03/31/11 11:57
03/31/11 11:57
|
Joined: Feb 2010
Posts: 320 TANA/Madagascar
3dgs_snake
Senior Member
|
Senior Member
Joined: Feb 2010
Posts: 320
TANA/Madagascar
|
Hi, If you create a class in a dll, you can access all its properties with a struct with the same signature. You just need to create plain functions in the dll to call class methods. To create an instance of a class, you create a function in the dll that returns the instance you want (you also need to call the destructor of the class in a similar function). ex : C++
class CObject
{
public:
// Constructor
CObject(int, int, int);
// Destructor
~CObject();
int a;
int b;
int c;
// Sample method
void foo();
}
/**
* Constructor
*/
CObject::CObject(int x, int y, int z)
{
this->a = x;
this->b = y;
this->c = z;
}
/**
* Destructor
*/
CObject::~CObject()
{
}
// Sample method
void CObject::foo()
{
this->c = this->a + this->b;
}
// Create instance of the class
DLLFUNC CObject *CObject_Create()
{
return new CObject();
}
DLLFUNC void CObject_Destroy(CObject *instance)
{
delete instance;
}
// This function will be called in lite-c
DLLFUNC void CObject_foo(CObject *instance)
{
// Call the function
instance->foo();
}
Lite - C
typedef struct CObject
{
int a;
int b;
int c;
}CObject;
// Create instance of the class
CObject *CObject_Create();
// Destroy instance of the class
void CObject_Destroy(CObject *instance);
// Call method foo
void CObject_foo(CObject *instance);
I think that will help you. OOps! too late again Best regards.
Last edited by 3dgs_snake; 03/31/11 11:58.
|
|
|
Re: What exactly is does "external only" mean referring to classes?
[Re: 3dgs_snake]
#365990
03/31/11 12:31
03/31/11 12:31
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Hey snake, just a short thing, your struct might not represent the real objects in memory. The memory layout is only guaranteed for POD types, the compiler might do some optimization on the memory layout of your class and then accessing 'a' might result in an access to 'b' and 'c' might point to some foobar variable introduced by the compiler or whatsoever.
Also remark that structs in Lite-C are always __attribute__((packed)), so you might have to add padding variables depending on your architecture into the struct
So yeah, it is definitely a source of evil and hard to debug bugs, so you might have to look for some other way for communication (beside that having public variables outside of POD types is also considered as a very bad style).
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: What exactly is does "external only" mean referring to classes?
[Re: WretchedSid]
#365991
03/31/11 12:41
03/31/11 12:41
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
infact almost most of the time, the a,b,c in your struct wont be the a,b,c from your instance, so just as i did, define your type as int, and only use pointers, and getters/setters.
3333333333
|
|
|
Re: What exactly is does "external only" mean referring to classes?
[Re: 3dgs_snake]
#366002
03/31/11 15:10
03/31/11 15:10
|
Joined: Aug 2000
Posts: 1,140 Baunatal, Germany
Tobias
Moderator
|
Moderator
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
|
It should be mentioned that lite-C only supports class methods, but no inherited methods. I found that out some time ago. So you need to define the inherited methods again in the lite-C class. You can see this in how the Direct X classes are defined in lite-C, like this:
#define INTERFACE IDirect3DTexture9
DECLARE_INTERFACE_(IDirect3DTexture9, IDirect3DBaseTexture9)
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IDirect3DBaseTexture9 methods ***/
STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice) PURE;
STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags) PURE;
STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid,void* pData,DWORD* pSizeOfData) PURE;
STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid) PURE;
STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew) PURE;
STDMETHOD_(DWORD, GetPriority)(THIS) PURE;
STDMETHOD_(void, PreLoad)(THIS) PURE;
STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS) PURE;
STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew) PURE;
STDMETHOD_(DWORD, GetLOD)(THIS) PURE;
STDMETHOD_(DWORD, GetLevelCount)(THIS) PURE;
STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType) PURE;
STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS) PURE;
STDMETHOD_(void, GenerateMipSubLevels)(THIS) PURE;
STDMETHOD(GetLevelDesc)(THIS_ UINT Level,D3DSURFACE_DESC *pDesc) PURE;
STDMETHOD(GetSurfaceLevel)(THIS_ UINT Level,void** ppSurfaceLevel) PURE;//IDirect3DSurface9
STDMETHOD(LockRect)(THIS_ UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) PURE;
STDMETHOD(UnlockRect)(THIS_ UINT Level) PURE;
STDMETHOD(AddDirtyRect)(THIS_ CONST RECT* pDirtyRect) PURE;
};
MY_DECLARE_INTERFACE(IDirect3DTexture9)
This defines the IDirect3DTexture9 class, but the IDirect3DBaseTexture9 is ignored in the DECLARE_INTERFACE definition. So all IDirect3DBaseTexture9 methods are declared again in the IDirect3DTexture9 class under lite-C.
|
|
|
|