Quantcast
Channel: VBForums - API
Viewing all 209 articles
Browse latest View live

Question about pipe sizes


[RESOLVED] double buffering: how use CreateBitmap()?

$
0
0
Code:

dim ImageBitmap as long
ImageBitmap = CreateBitmap(width, height, 1, 32, 0)
If (ImageBitmap = 0) Then Debug.Print "error on ImageBitmap"

why i get zero on ImageBitmap?
what i'm doing wrong for create the bitmap?

transparentblt: don't work with transparent colors?

$
0
0
transparentblt() is limited with some colors?
what i means is that, using gif files, i'm trying draw the image transparent with a diferent result on draw(i use white, but i lose the black).
can anyone explain to me?

What exactly are the size of the fields in the WSADATA structure?

$
0
0
Or I guess, I should be asking "what size should they be when using Winsock API in VB6?". I'm trying to use Winsock API, and I need to know exactly how to define the User Defined Type of WSADATA in VB6. According to winsock2.h as found at https://gist.github.com/piscisaureus/906386 the field szDescription is supposed to be a char array (what VB6 calls a Byte array), of length WSADESCRIPTION_LEN+1 (total length is 257 bytes), where WSADESCRIPTION_LEN=256. And the szSystemStatus field is a char array of length WSASYS_STATUS_LEN+1 (total length 129), where WSASYS_STATUS_LEN=128. Problem is VB6 does not like odd-number sized fields like 257 or 129, and will apply padding bytes automatically. How do I get around this problem when implementing Winsock API in VB6? Is Winsock API simply impossible to use in VB6?

Api dll

$
0
0
Friends, im new to visual studio, i have Frea 300 with a manual to program visual basic. it is having FRJ_API.dll file. i want to import it as add reference in visual studio 2015. but it is giving me an error " A reference to 'c;\ FRJ_API.dll' could not be added. please make sure that the file is accessible, and that it is a valid assembly or COM component" ... I tried to surf google but not get the solution. The file is attached with this post... i want to access the functions to monitor and control parameters of Freja testing equipment. your help is appreciated.. thanks and regards..
Attached Files

[RESOLVED] transparentblt: don't work with transparent colors?

$
0
0
transparentblt() is limited with some colors?
what i means is that, using gif files, i'm trying draw the image transparent with a diferent result on draw(i use white, but i lose the black).
can anyone explain to me?

[RESOLVED] Trouble extracting Checkbox State from external application

$
0
0
I am trying to determine the state of a checkbox in an external program from a VB.Net WinForm application. I used Spy++ to get the handle of the checkbox. I convert the handle from hex to decimal, and enter it into a textbox (I automatically extract the handle in my full application). I can toggle the checkbox from my program, so I know i have the correct handle. However I can not seem to GETSTATE or GETCHECK using SendMessage. I was not sure which I should be using, but they both always return 0. Here is my module code:


Code:

Imports System.Runtime.InteropServices
Module Module1

    Public Const BM_CLICK = &HF5
    Public Const BM_GETCHECK = &HF0
    Public Const BM_GETSTATE = &HF2

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Private Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    End Function

    Sub toggle(hwnd As IntPtr)
        SendMessage(hwnd, BM_CLICK, 0, 0)
    End Sub

    Function GetCheck(hwnd As IntPtr) As Integer
        Return SendMessage(hwnd, BM_GETCHECK, 0, 0)
    End Function

    Function GetState(hwnd As IntPtr) As Integer
        Return SendMessage(hwnd, BM_GETSTATE, 0, 0)
    End Function
End Module

and my form code

Code:

Public Class Form1
    Private Sub btnToggle_Click(sender As Object, e As EventArgs) Handles btnToggle.Click
        Dim hwnd As IntPtr = CType(TextBox1.Text, IntPtr)
        toggle(hwnd)
    End Sub

    Private Sub btnGetStatus_Click(sender As Object, e As EventArgs) Handles btnGetStatus.Click
        Dim hwnd As IntPtr = CType(TextBox1.Text, IntPtr)
        lblState.Text = GetState(hwnd).ToString
    End Sub

    Private Sub btnGetChk_Click(sender As Object, e As EventArgs) Handles btnGetChk.Click
        Dim hwnd As IntPtr = CType(TextBox1.Text, IntPtr)
        lblCheck.Text = GetCheck(hwnd).ToString
    End Sub
End Class

Any help would be appreciated

[help] move mouse with sendinput

$
0
0
[Visual basic 2010]

Hello.. before i explain i need to say that i searched and searched and searched all over the web and didnt find what i want.

I want to move the mouse with sendinput since mouse_event is deprecated and i dont wanna use Cursor.position.

So how would i move the mouse with something i hear everyone talking about (sendinput api) but nobody giving and example.

Thanks

How do you get raw mouse data?

$
0
0
Windows translates raw mouse movement data into a change in position on the screen. You can read the current position on the screen of the cursor with GetCursorPos. However I want to read the raw mouse input data. Raw mouse data though aren't absolute coordinates. They instead are a SPEED value (not a position value). That is, the raw mouse data will tell you how fast the mouse is moving horizontally and vertically. Is there any Windows API function that I can use to poll the mouse for its current X and Y speed values?

Can somebody show an example of reading data from a USB device, via WinUsb?

$
0
0
I am writing a VB6 program that communicates with a device where the manufacturer only created a driver for Android, but not Windows. I've installed the WinUsb driver as the driver for this device in Windows. This gives me the ability to directly communicate with the device, via the use of the WinUsb API functions. I've already figured out the data packets being sent, based on some reverse engineering going on on another forum (eevblog), so I know what data to expect to receive from this device (and even what data the device expects the computer to send to it, during its "handshake", so as to initiate the stream of data from the external device to the computer).

However that other website where the hardware is being reverse engineered (for the ultimate purpose of being able to let Windows computers use the device) just has a bunch of people using Linux, and I need to implement the same things in Windows (using VB6). It seems that in the process of reverse engineering a piece of external hardware, people LOVE to use Linux as the OS from which they test the device to be reverse engineered. Fortunately, Windows has the WinUsb driver, which should make porting the Linux code to Windows a fairly straight forward task (or at least I hope it does). The problem though is that I don't know how to read and write raw data from the USB port using WinUsb. I know I CAN do it through WinUsb, but I don't know HOW to do it. Big difference between knowing I CAN, versus knowing HOW to, do something.

If anybody on this forum is intimately familiar with the usage of WinUsb, please help me out here.

Problem with FreeLibrary in VB6 IDE

$
0
0
FreeLibrary doesn't free a loaded DLL in VB6.

If I load a DLL file with LoadLibrary, get a function pointer with GetProcAddress, and then call the function with DispCallFunc, it runs that function. If I then remove the DLL from memory using FreeLibrary, and then again try to call that same function using DispCallFunc, it should at least fail to work, and at most crash completely. However, I found out shockingly that the function runs just fine! This indicates that the DLL was NOT unloaded from memory, and that the memory that the DLL occupied was NOT freed/deallocated (which wastes memory space, keeping a DLL in memory that no longer needs to be in memory). And it doesn't matter how many times I call FreeLibrary. I can call it from a command button, and click that button 100 times, but it NEVER frees the DLL from memory. It's like the DLL file is STUCK in memory.

When I save an EXE file of the same program that I'd been working on in VB6, and then run it, and do the same tests on the DLL file from within the EXE file (rather than from within VB6) the FreeLibrary command works as expected, removing the DLL file from memory. Only in the VB6 IDE itself does FreeLibrary fail to remove the DLL file from memory.

Is there some kind of GetDIBitsFromDevice?

$
0
0
For setting DIB bits SetDIBits and SetDIBitsToDevice.
For getting DIB bits though there's only GetDIBits, at least as far I have seen.

Is there some kind of undocumented GetDIBitsFromDevice function that exists? SetDIBitsToDevice is a very powerful function (far more than just SetDIBits), because it allows you to take any rectangular portion of an image, who's pixels are represented by a byte array, and paste it anywhere in a displayed image (where that displayed image is represented by a DC). I would like to be able to do the reverse of this, take any portion of a displayed image, and copy it into byte array. GetDIBits does not have the ability to select a rectangular portion of an image displayed in a DC. GetDIBits only allows you to capture the entire displayed image (whether that image is the screen, or just one window on the screen).

Yes, I could use a set of functions like creating a new DC and associated DIB, and then BitBlt a portion of the source into the new DC, and then in turn use GetDIBits to get a byte array copy of that new DC that I had created, but that seems like unnecesary extra work. If a single function like SetDIBitsToDevice can be used for setting only a portion of the pixels in a displayed image, it seems only logical that there would be (and should be) an equivalent function to get only a portion of the pixels within an image.

Is there anyway to determine when an external app changes

$
0
0
I would like to be alerted when the contents on an external app changes in any way (such as a textbox value changing). I currently know how to discover the various windows identifiers and read the text property of textboxes and labels, but right now I have to iteratively poll the site to see if anything changes, which is not very efficient. i wondered if there is anything I can set which will monitor the application level window and trigger an event in my code if any content on the external page changes.

Separately, is there any event log file that is automatically generated on a running application, and if so how can it be accessed? I am not aware of anything like this, but my research keeps mentioning a log file, and I was not sure if this is something that the programmer has to implement or if windows does it by itself. Any input would be appreciated.

Run exe file and wait until it exits

$
0
0
I have tried multiple versions of code found by my friend Mr Google to do this. They all run the program but none of them wait until it is closed. They work with notepad.exe though. Any ideas as to why this might be and how I can make VB6 wait?

autoleveller-0.8.7.exe https://www.autoleveller.co.uk/
Windows 10 64 bit

Some questions about GetDIBits and SetDIBits functions

$
0
0
Why do these functions have separate arguments for hDC and Bitmap handles? Since the Bitmap is going to be selected into the DC, why don't these functions just use the DC's handle (the hDC) for getting at the image data. Why do these functions require 2 separate handles? And what information about the image do they get from each of these objects (the DC, and the Bitmap)? Furthermore, why do these functions then further also require a BitmapInfoHeader structure to be passed to them? Don't these functions get all the info they need about the picture in question from the Bitmap and DC objects, who's handles you pass to these functions?

Since you pass separate DC and Bitmap handles to the GetDIBits and SetDIBits functions, does the Bitmap not need to be selected into the DC, when using these functions? Can I just use GetDC(0) to get the main screen's DC, or CreateCompatibleDC(0) to create a temporary DC, to act as a kind of "dummy" DC for filling the hDC argument in the GetDIBits or SetDIBits functions, while the actual Bitmap (who's bits I want to Get or Set) is on its own (not selected into the DC)?

Window on Top of Screen

$
0
0
Hi,

I am using API (VBA Excel v2106) to activate a workbook. In my example below I try to activate "Book3.xlsx".

Issue:
- Function lhWndWorkbookWindow() returns 0 if the workbook isn't already active.

NOTE!
In reality I am trying to activate correct workbook in Excel from coding in VBA Microsoft Access. I just wanted to simplify my case for this forum. It's the same issue having the code directly in VBA Excel.


Code:

'Show Application/Window on top of screen
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long

'Find a child window with a given class name and caption
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) _
As Long

Sub ActivateMyWkb()
   
    Dim lhWndExcelWkb As Long
   
    'Activate "Book3.xlsx"
    lhWndExcelWkb = lhWndWorkbookWindow(Windows("Book3.xlsx"))
    BringWindowToTop (lhWndExcelWkb)
End Sub

Function lhWndWorkbookWindow(ByRef wndWindow As Window) As Long
'Get handle of Excel Workbook

    Dim lhWndExcel As Long
    Dim lhWndDesk As Long

    'Get the main Excel window
    lhWndExcel = Application.hwnd

    'Find the desktop
    lhWndDesk = FindWindowEx(lhWndExcel, 0, "XLDESK", vbNullString)

    'Find the workbook window
    lhWndWorkbookWindow = FindWindowEx(lhWndDesk, 0, "EXCEL7", wndWindow.Caption)
End Function

*OleServerBusyTimeout* and *OLEServerBusyRaiseError* API alternatives ?

Question about FourCCs and ICOpen function

$
0
0
According to https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx there are 3 fields to ICOpen, the first of which requires an "type" FourCC to tell it what type of compressor (audio or video) is being requested for opening. If it's video, it must have the FourCC "VIDC" according to MSDN, but MSDN never tells the proper way to convert this string to a number. Notice that the FourCCs in ICOpen require a 4byte integer for input, not a four character string. So there's 2 possible ways to convert the string "VIDC" to an integer.

1:
Treat the string in memory as if it is an integer. The leftmost character corresponds to the least significant byte of the integer. For "VIDC", this corresponds to the integer 0x43444956

2:
Treat the string as if it is a number being displayed, with the leftmost character corresponding to the most significant byte of the value. For "VIDC", this corresponds to the integer 0x56494443

I'm not sure which way is the correct way to convert a string to a FourCC. I want to do it right, so I don't crash my program when it tries to execute ICOpen, as in VB6, any time you encounter an API error, the entire VB6 IDE crashes. Normally, if I was just working with pure VB functions, I'd just try both ways, to see which worked, but I'm working with API functions here and I don't want to crash the IDE.

[RESOLVED] What does hwnd2 means?

$
0
0
I'm quite confused on my project I use Spy++. What do you call the child window having another child window? If I'm using FindWindowEx does it mean I need to create another one?! I know that hwnd1 is for parent window handler, but I can not figure out what is hwnd2... Can I assign 2 parents on FindWindowEx or do I define the 1st child window as another FindWindowEx and not FindWindow?! The textbox I'm looking at, is inside a frame window and Spy++ can not determine the class of that frame window... And that frame is inside the 1st child window... So I assume that the textbox belong to the 1st child window...

WM_KEYDOWN and WM_KEYUP Conversion to PostMessage or Send Message

$
0
0
Have this captured which uses a Virtual Key...ugh. Can someone please help me understand what the formatting would be to leverage SendMessage or PostMessage. I have the proper handle and postresult is returning 1, but the target app is not accepting the messages. It's late and I must be overlooking something, thanks for any insight!

postresult = PostMessage(pgHandle, WM_KEYDOWN, ByVal Asc("3"), 1&)


Name:  SpyResultsKey3.jpg
Views: 202
Size:  8.2 KB
Attached Images
 
Viewing all 209 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>