Need help with 'C' Declaration

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Eikeland.

Hi,
I do something toal wrong with mine transelation of the code below, so may I ask if someone please could take a look at this, how would this be corectly transelated to PB?

Thanks a million! :)
Richard

Structures:
typedef struct _CM_CODETIPDATA {
NMHDR hdr;
HWND hToolTip;
UINT nTipType;
} CM_CODETIPDATA, *LPCM_CODETIPDATA;

typedef struct _CM_CODETIPFUNCHIGHLIGHTDATA {
CM_CODETIPDATA ctData
UINT nArgument;
} CM_CODETIPFUNCHIGHLIGHTDATA, *LPCM_CODETIPFUNCHIGHLIGHTDATA;

typedef struct _CM_CODETIPHIGHLIGHTDATA {
CM_CODETIPDATA ctData
UINT nHighlightStartPos;
UINT nHighlightEndPos;
} CM_CODETIPHIGHLIGHTDATA, *LPCM_CODETIPHIGHLIGHTDATA;

typedef struct _CM_CODETIPMULTIFUNCDATA {
CM_CODETIPFUNCHIGHLIGHTDATA ctfData;
UINT nFuncCount;
UINT nCurrFunc;
} CM_CODETIPMULTIFUNCDATA, *LPCM_CODETIPMULTIFUNCDATA

Sample Function:

BOOL OnCodeTipInitialize( LPCM_CODETIPDATA lpctd )
{
switch( lpctd->nTipType )
{
case CM_TIPSTYLE_NORMAL:
{
// Do something with lpctd...
}
break;

case CM_TIPSTYLE_HIGHLIGHT:
{
LPCM_CODETIPHIGHLIGHTDATA pData =
(LPCM_CODETIPHIGHLIGHTDATA) lpctd;

// Highlight some text...
pData->nHighlightStartPos = 0;
pData->nHighlightEndPos = 5;
}
return TRUE;

case CM_TIPSTYLE_FUNCHIGHLIGHT:
{
LPCM_CODETIPFUNCHIGHLIGHTDATA pData =
(LPCM_CODETIPFUNCHIGHLIGHTDATA) lpctd;

// Highlight a function argument...
pData->nArgument = 3;
}
return TRUE;

case CM_TIPSTYLE_MULTIFUNC:
{
LPCM_CODETIPMULTIFUNCDATA pData =
(LPCM_CODETIPMULTIFUNCDATA) lpctd;

// Highlight a function argument...
pData->ctfData.nArgument = 3;

// This function has one overload in addition to
// the normal prototype, i.e.:
//
// void SomeFunc() nFuncCount = 1; // Number of overloads

// Default to normal prototype
pData->nCurrFunc = 0; // Zero-based index of prototype
}
return TRUE;
}

// We didn't change any structure members...
return FALSE;
}
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Code: Select all

Structure CM_CODETIPDATA  hdr.NMHDR
  hToolTip.l
  nTipType.l
EndStructure

Structure CM_CODETIPFUNCHIGHLIGHTDATA
  ctData.CM_CODETIPDATA
  nArgument.l
EndStructure

Structure CM_CODETIPHIGHLIGHTDATA
  ctData.CM_CODETIPDATA
  nHighlightStartPos.l
  nHighlightEndPos.l
EndStructure

Structure CM_CODETIPMULTIFUNCDATA 
  ctfData.CM_CODETIPFUNCHIGHLIGHTDATA
  nFuncCount.l
  nCurrFunc.l
EndStructure


Procedure OnCodeTipInitialize( *lpctd.CM_CODETIPDATA )

Select *lpctd\nTipType
  Case #CM_TIPSTYLE_NORMAL
    ; Do something with lpctd...

    result = 0

  Case #CM_TIPSTYLE_HIGHLIGHT
  
    *pData.CM_CODETIPHIGHLIGHTDATA = *lpctd
    *pData\nHighlightStartPos = 0
    *pData\nHighlightEndPos = 5
    
    result = #True

  Case #CM_TIPSTYLE_FUNCHIGHLIGHT
    
    *pData.CM_CODETIPFUNCHIGHLIGHTDATA = *lpctd
    *pData\nArgument = 3
    
    result = #True

  Case #CM_TIPSTYLE_MULTIFUNC
  
    *pData.CM_CODETIPMULTIFUNCDATA = *lpctd
    *pData\ctfData.nArgument = 3

    *pData\nFuncCount = 1  
    *pData\nCurrFunc = 0
    
    result = #True

  Default
    result = #False
    
EndSelect

ProcedureReturn result
EndProcedure

--------------------------------------

Note:
As you can't exit a procedure within Select/Endselect in PureBasic, i inserted the 'result = ' instead of the return/break commands, and 'result' is then returned by ProcedureReturn an the end.

All the Constants like #CM_TIPSTYLE_HIGHLIGHT are not defined yet in your program. You need to find out their values from the C source (maybe in some header file) and define them in you PB source, too.

Hope I made no mistake...

Timo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

With PB 3.62, you can now exits a procedure directly in a Select/EndSelect. Your way is the recommanded one: only one exit point for a given procedure.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

why not multiple exit points now that pb supports it?, it shoudn't be faster?

once a case is evaluated to true, are the rest evaluated or does the select exit?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

That's a matter of taste. Personnaly, I don't like several exit points... Feel free to do it if you want ! About the performance boost, it's a very very little faster (may be 2 opcode) but it produces bigger code.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

ok thanks, how about the 2nd question? , are all the cases always reached?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

Will this answer do, Justin?

Code: Select all

a = 1
Select a
  Case 0
    Debug "0"
  Case 1
    Debug "1"
  Case 1
    Debug "1a"
  Case 2
    Debug "2"
EndSelect
You only get the debug output "1", which in my eyes means that no further checking occurs after a case that fits the condition you've set has been found..
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Eikeland.

Thanks!
..darn it still not working.
for some reason the controll I'm calling does not recieve the pointers.
I guess I'm out on thin ice here but do you think it could be solve with a CopyMemory function?

Richard
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Yep, once a case is true, it exits the select.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

yes Pupil, that answer my question, thanks both.
Post Reply