PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 10
 1 
 on: June 24, 2017, 04:29:57 PM 
Started by jermy - Last post by Pierre Bellisle
Another way...

Pierre

Code: [Select]
'\64\fbc.exe -s console -w pedantic

#Lang "fb"
#Define Unicode
#Include once "windows.bi"
#Include once "win\winsock2.bi"
'_____________________________________________________________________________

Function GetString(ByVal lpSZA as zString Pointer) as String  'Convert a ZSTRING to a Dynamic string

 'One way... Dim As String sGetString = String$(lstrlenA(Cast(LPTSTR ,lpSZA)), 0) 'Build a big enought dynamic string
 'One way... Dim As LPTSTR pString = StrPtr(sGetString) 'Get the pointer of the dynamic string
 'One way... lStrCpyA(pString, Cast(LPTSTR, lpSZA)) 'Copy the ZSTRING to the dynamic string
 'One way... FUNCTION = *pString 'Set the dynamic string content to the function

 FUNCTION = *lpSZA 'Set the dynamic string content to the function

End Function
'_____________________________________________________________________________

Function GetInetAddrStr01(ByVal Address as DWORD) as String 'Pointer
 Dim inAddr As in_addr

 inAddr.S_addr = Address
 Function = GetString(inet_ntoa(inAddr))
 
End Function
'_____________________________________________________________________________

Function GetInetAddrStr02(ByVal Address as DWORD) as String
 Dim inAddr As in_addr

 inAddr.S_addr = Address
 Function = *inet_ntoa(inAddr)

End Function
'_____________________________________________________________________________

Print GetInetAddrStr01(&h04030201)
Print GetInetAddrStr02(&h01020304)
Print

Print "Press a key or click to end" : Dim buttons As Long
Do : GetMouse(0, 0, 0, Buttons) : IF buttons Or Len(InKey) Then Exit Do : End If : Sleep 200 : Loop
'_____________________________________________________________________________
'

 2 
 on: June 24, 2017, 06:52:17 AM 
Started by jermy - Last post by jermy
lpszA = Long Pointer String z? ansi

Now i see it, its a ugly vb6 work around.

Code: [Select]
Declare Function lstrlenA Lib "kernel32" (ByVal lpString as Long) as Long  ''' Determines the length of the specified string (not including the terminating null character)
Declare Function inet_ntoa Lib "wsock32.dll" (ByVal addr as Long) as Long  ''' The inet_ntoa function converts an (Ipv4) Internet network address into an ASCII string in Internet standard dotted-decimal format.
' If no error occurs, inet_ntoa returns a character pointer to a static buffer containing the text address in standard ".'' notation. Otherwise, it returns NULL.

 
Function GetInetAddrStr(Address as Long) as String

  GetInetAddrStr = GetString(inet_ntoa(Address))   
 
End Function

Function GetString(ByVal lpszA as Long) as String
 
  ' GetString = String$(lstrlenA(ByVal lpszA), 0)      'vb6 syntax
  ' GetString = String$(Len(lpszA), 0)

 ' Call lstrcpyA(ByVal GetString, ByVal lpszA)      'vb6 syntax
'  lstrcpyA(ByVal GetString, ByVal Cast(String, lpszA))
 
End Function


most vb6 programs i can copy and paste to freebasic, this one got some ugly work around, its better to start all over again.  ;D

 3 
 on: June 23, 2017, 08:49:54 PM 
Started by jermy - Last post by Pierre Bellisle
Hi Jermy,

I guess you think of something like this... Is that it?

Pierre

Code: [Select]
Function GetString(ByVal lpSZA as LPTSTR) as String  'Convert a ZSTRING to a Dynamic string

 'One way... Dim As String sGetString = String$(lstrlenA(Cast(LPTSTR ,lpSZA)), 0) 'Build a big enough dynamic string
 'One way... Dim As LPTSTR pString = StrPtr(sGetString) 'Get the pointer of the dynamic string
 'One way... lStrCpyA(pString, Cast(LPTSTR, lpSZA)) 'Copy the ZSTRING to the dynamic string
 'One way... FUNCTION = *pString 'Set the dynamic string content to the function

 FUNCTION = *lpSZA 'Set the dynamic string content to the function

End Function

Dim As ZString * 50 zs = "123"
? GetString(@zs)

 4 
 on: June 23, 2017, 11:51:08 AM 
Started by jermy - Last post by Josť Roca
> What am I doing wrong?

Everything, beginning with trying to use a VB syntax with FB.

Can we know what are you passing in the lpszA parameter? Maybe a pointer to a null terminated string? I strongly doubt that with FB you will need to use lstrcpy to simply copy a string.

 5 
 on: June 23, 2017, 11:20:19 AM 
Started by jermy - Last post by jermy
Hello,


I'm translating a program from vb6 to freebasic, I'm stuck with this piece of code.
the compiler telles me 'Argument count mismatch' ?

Code: [Select]
' Declare Function lstrcpyA Lib "kernel32" (ByVal RetVal As String, ByVal Potr As Long) As Long     'vb6 syntax

Function GetString(ByVal lpszA as Long) as String
 
  ' GetString = String$(lstrlenA(ByVal lpszA), 0)    'vb6 syntax
  GetString = String$(Len(lpszA), 0)

  ' Call lstrcpyA(ByVal GetString, ByVal lpszA)      'vb6 syntax
  lstrcpy(ByVal GetString, ByVal Cast(String, lpszA))
 
End Function

What am I doing wrong?

 6 
 on: June 22, 2017, 07:17:58 PM 
Started by James Klutho - Last post by James Klutho
Thanks Jose

 7 
 on: June 22, 2017, 07:05:59 PM 
Started by James Klutho - Last post by Josť Roca
I think that, by default, GDI+ uses UnitDisplay as the unit of measurement. If the display device is a monitor, then the unit is 1 pixel, but for printers it uses 100 of inches (see DIM cx AS LONG = GetDeviceCaps(hdcPrint, HORZRES) / (dpiX / 100) in my AfxGdipPrintHBITMAP function). To use the same coordinates, call the GdipSetPageUnit function (see http://www.jose.it-berater.org/gdiplus/reference/flatapi/graphics/gdipsetpageunit.htm ) passing the constant UnitPixel (see https://msdn.microsoft.com/en-us/library/windows/desktop/ms534405(v=vs.85).aspx ).

 8 
 on: June 22, 2017, 03:47:02 PM 
Started by James Klutho - Last post by James Klutho
Well I found my bitmap printing problem and programmed a kludge to fix it.  It turns out the when printing in GDI+, even though the device context may be a printer with 600 dpi, GDI+ expects the location to be is SCREEN RESOLUTION (or something close to that).  I was always printing off the page.  The below code prints the bitmap in the middle of the page whereas a GDI printer device context would be in the upper left hand corner.  Wow, I used a ream of paper to figure this out.  Jim

    'hDC is a printer DC
    GdipCreateFromHDC(hDC, @pGraphics)
    GdipCreateBitmapFromHBITMAP(hbmp, NULL, @pBitmap)
    GdipDrawImage(pGraphics, CAST(GpImage PTR, pBitmap), 400, 600)

 9 
 on: June 21, 2017, 08:31:03 PM 
Started by James Klutho - Last post by James Klutho
I saw the negative width and height on quite a few examples on the internet that rotated objects (which I want to do) and I don't understand it.  I tried positive numbers but no luck when I rotated and modified the world.  This is why I said I don't understand GDI+.  The way I have it works fine to a screen DC to display a bitmap but printers seem to fail on it.  There has to be a way to rotate a bitmap map that works on both screen and a printer.  The code I have fails at home printers and on the networked printers at work.

Thanks for looking at it.

 10 
 on: June 21, 2017, 03:59:32 PM 
Started by James Klutho - Last post by Josť Roca
BTW I prefer to use GdiPlus only, e.g.

Code: [Select]
#define UNICODE
#INCLUDE ONCE "Afx/CWindow.inc"
#INCLUDE ONCE "Afx/AfxPrinter.inc"
#INCLUDE ONCE "Afx/CGdiPlus/CGdiPlus.inc"
USING Afx

Code: [Select]
DIM docInfo AS DOCINFOW
docInfo.cbSize = sizeof(DOCINFOW)
DIM wszDocName AS WSTRING * 260 = "GdiplusPrint"
docInfo.lpszDocName = cast(LPWSTR, @wszDocName)
DIM hdcPrint AS HDC = CreateDCW(NULL, AfxGetDefaultPrinter, NULL, NULL)
IF hdcPrint THEN
   StartDoc(hdcPrint, @docInfo)
   StartPage(hdcPrint)
   DIM graphics AS CGpGraphics = hdcPrint
   ' // Get the DPIs of the printer
   DIM dpiX AS SINGLE = graphics.GetDpiX
   DIM dpiY AS SINGLE = graphics.GetDpiY
   ' // Calculate the width and height according to the DPIs of the printer
   DIM cx AS LONG = GetDeviceCaps(hdcPrint, HORZRES) / (dpiX / 100)
   DIM cy AS LONG = GetDeviceCaps(hdcPrint, VERTRES) / (dpiY / 100)
   ' // ---------------------------------------------------
   DIM pen AS CGpPen = CGpPen(GDIP_ARGB(255, 0, 0, 0))
   graphics.DrawLine(@pen, 50, 50, 350, 550)
   graphics.DrawRectangle(@pen, 50, 50, 300, 500)
   graphics.DrawEllipse(@pen, 50, 50, 300, 500)
   ' // ---------------------------------------------------
   EndPage(hdcPrint)
   EndDoc(hdcPrint)
   DeleteDC(hdcPrint)
END IF

Pages: [1] 2 3 ... 10