-
Posts
902 -
Cadastrado em
-
Última visita
Tipo de conteúdo
Artigos
Selos
Livros
Cursos
Análises
Fórum
Tudo que Cambalinho postou
-
C++ como calcular o raycasting quadrado a quadrado?
Cambalinho respondeu ao tópico de Cambalinho em C/C#/C++
consegui, na linha horizontal para baixo, mas erra para cima If (Player.Radians < PI And Player.Radians > 0) Then 'facing down YA = ((Player.PosY \ ObjectSize) * ObjectSize) + ObjectSize XA = Player.PosX + (Player.PosY - YA) / -Tan(Player.Radians) Else If (Player.Radians > PI / 2 And Player.Radians > 0) Then 'facing up YA = ((Player.PosY \ ObjectSize) * ObjectSize) - ObjectSize XA = Player.PosX + (Player.PosY - YA) / -Tan(Player.Radians) End If ok... agora o codigo não é C... mas não interessa... preciso de saber: 1 - como verifico se o radiano esta para cima ou para baixo? 2 - como calcular para obter o ponto A(é o quadrado seguinte ao jogador mantendo o radiano)? Moderador: porque falham as teclas direcionais ao escrever? -
Visual Basic VB6 - como evitar 1 erro na criação de DIB's?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
nunca pensei que este erro meu podesse influenciar este erro: sempre que usamos 'set' ou 'new', temos de igual a variavel a 'nothing' com 'set'... e foi este meu erro, que causava o erro número 8. muito obrigado -
Visual Basic VB6 - como evitar 1 erro na criação de DIB's?
Cambalinho postou um tópico em Programação - outros
eu tenho 1 classe em VB6 para criar DIB's: Private Function AlignScan(ByVal inWidth As Long, ByVal inDepth As Integer) As Long AlignScan = (((inWidth * inDepth) + &H1F) And Not &H1F&) \ &H8 End Function Public Function NewImage(ByVal ImageWidth As Long, ByVal ImageHeight As Long, Optional color As ColorConstants = vbBlack) As Long If (Width > 0 Or Height > 0 Or hBitmap > 0 Or PointerPixelData > 0) Then DeleteImage Width = ImageWidth Height = ImageHeight 'Criar HDC MemoryHDC = CreateCompatibleDC(0) With bmiInfo.bmiHeader .biSize = Len(bmiInfo.bmiHeader) .biWidth = Width .biHeight = -Height ' is negative for start on top left pixel image .biPlanes = 1 .biBitCount = 32 .biCompression = BI_RGB .biSizeImage = AlignScan(bmiInfo.bmiHeader.biWidth, bmiInfo.bmiHeader.biBitCount) * bmiInfo.bmiHeader.biHeight End With If MemoryHDC = 0 Then MsgBox "error: HDC not created!!!" hBitmap = CreateDIBSection(0&, bmiInfo, DIB_RGB_COLORS, PointerPixelData, 0&, 0&) If hBitmap = 0 Then MsgBox "error: " & GetLastError() oldBitmap = SelectObject(MemoryHDC, hBitmap) 'using pointers: ' Get the bits in the from DIB section: With tSA .fFeatures = FADF_FIXEDSIZE Or FADF_AUTO .cbElements = 4 .cDims = 1 .Bounds(0).lLbound = 0 .Bounds(0).cElements = bmiInfo.bmiHeader.biHeight * bmiInfo.bmiHeader.biWidth .pvData = PointerPixelData End With 'Erase bDib ' Make the bDib() array point to the memory addresses: CopyMemory ByVal VarPtrArray(bDib()), VarPtr(tSA), 4 CopyMemory ByVal VarPtrArray(bDibBGRA()), VarPtr(tSA), 4 'Clear color End Function 'e como limpar: Public Sub DeleteImage() 'Clear pointer: Dim z As Long CopyMemory ByVal VarPtrArray(bDib), VarPtr(z), 4 Erase bDib Dim s As Long CopyMemory ByVal VarPtrArray(bDibBGRA), VarPtr(z), 4 Erase bDibBGRA SelectObject MemoryHDC, OldBrush DeleteObject NewBrush SelectObject MemoryHDC, OldPen DeleteObject NewPen SelectObject MemoryHDC, oldBitmap DeleteObject hBitmap 'ReleaseDC 0, MemoryHDC DeleteDC MemoryHDC End Sub o meu problema é: após 4 execuções no IDE(mas não acontece no EXE), eu obtenho 1 erro nesta linha: Public Function NewImage(ByVal ImageWidth As Long, ByVal ImageHeight As Long, Optional color As ColorConstants = vbBlack) As Long If (Width > 0 Or Height > 0 Or hBitmap > 0 Or PointerPixelData > 0) Then DeleteImage Width = ImageWidth Height = ImageHeight 'Criar HDC MemoryHDC = CreateCompatibleDC(0) With bmiInfo.bmiHeader .biSize = Len(bmiInfo.bmiHeader) .biWidth = Width .biHeight = -Height ' is negative for start on top left pixel image .biPlanes = 1 .biBitCount = 32 .biCompression = BI_RGB .biSizeImage = AlignScan(bmiInfo.bmiHeader.biWidth, bmiInfo.bmiHeader.biBitCount) * bmiInfo.bmiHeader.biHeight End With If MemoryHDC = 0 Then MsgBox "error: HDC not created!!!" hBitmap = CreateDIBSection(0&, bmiInfo, DIB_RGB_COLORS, PointerPixelData, 0&, 0&) If hBitmap = 0 Then MsgBox "error: " & GetLastError() 'ERRO: não cria o DIB... erro 8: "ERROR_NOT_ENOUGH_MEMORY 8 (0x8) Not enough memory resources are available to process this command." https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- porquê este erro? porque só aparece após executar 4 vezes no IDE e não no EXE? para voltar a executar, eu tenho de terminar\fechar o IDE e voltar a executar... estranho este erro -
Visual Basic Raycasting: como calcular o tamanho da linha vertical?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
finalmente consegui resultados mais corretos: Public Function BresenhamLine(X0 As Long, Y0 As Long, X1 As Long, Y1 As Long, ByRef Map() As Long, ObjectSize As Long, angle_rad As Double) As Long Dim dx As Long Dim dy As Long Dim steps As Double Dim Xincrement As Double Dim Yincrement As Double Dim x As Double Dim y As Double Dim MapX As Integer Dim MapY As Integer Dim LineWidth As Long x = X0 y = Y0 dx = X1 - X0 dy = Y1 - Y0 LineWidth = 0 If (Abs(dx) > Abs(dy)) Then steps = Abs(dx) Else steps = Abs(dy) End If Xincrement = dx / (steps) Yincrement = dy / (steps) Dim v As Integer For v = 0 To steps x = x + Xincrement y = y + Yincrement MapX = Int(x / ObjectSize) MapY = Int(y / ObjectSize) LineWidth = LineWidth + 1 If (Map(MapY, MapX) = vbBlue) Then Exit For End If Next v ForeColor vbRed DrawLine X0, Y0, Int(x), Int(y) 'Calculate the Distance between Origin and Destination line: 'CatetoAdjacente=(x - X0) 'CatetoOposto=(y - Y0) 'Hip = RaizQuadrada(CatetoAdjacente ^ 2 + CatetoOposto ^ 2) LineWidth = Sqr((x - X0) * (x - X0) + (y - Y0) * (y - Y0)) BresenhamLine = LineWidth End Function Public Function DrawLineWithAngleAndLength(X1 As Long, Y1 As Long, angle_rad As Double, Length As Long, Map() As Long, ObjectSize As Long) As Long ' Calcular as coordenadas finais da linha Dim X2 As Long Dim Y2 As Long X2 = X1 + Length * Cos(angle_rad) Y2 = Y1 + Length * Sin(angle_rad) ' Chame a função BresenhamLine com as coordenadas finais DrawLineWithAngleAndLength = BresenhamLine(X1, Y1, X2, Y2, Map(), ObjectSize, angle_rad) End Function Private Sub DrawRays(StartRadians As Double, EndRadians As Double, VisionRadians As Double, ScreenWidth As Long, Optional Precision As Long = 1) Dim RayCount As Long Dim RaySteps As Double Dim RayWay As Long Dim RayWidth As Long Dim RayAngle As Double Dim RayHeight As Double 'number of rays: RayCount = ScreenWidth / CLng(VisionRadians) * Precision 'getting increment ray: RaySteps = (EndRadians - StartRadians) / CDbl(RayCount) Do While (RayWay < RayCount) 'calcule the ray angle\radians: RayAngle = StartRadians + (RaySteps * RayWay) 'draw ray and get ray width: RayWidth = A.DrawLineWithAngleAndLength(Int(Player.PosX), Int(Player.PosY), RayAngle, 300, LevelMap0(), 33) RayHeight = 66 / RayWidth * ScreenWidth A.ForeColor vbBlue A.DrawLine 475 + 50 + RayWay, 200 / 2 - RayHeight / 2, 475 + 50 + RayWay, 200 / 2 + RayHeight / 2 RayWay = RayWay + 1 Loop End Sub eu sei que os cálculos estão corretos, porque agora obtenho resultados esperados... eis como obtenho a altura de linha: 'draw ray and get ray width: RayWidth = A.DrawLineWithAngleAndLength(Int(Player.PosX), Int(Player.PosY), RayAngle, 300, LevelMap0(), 33) RayHeight = 66 / RayWidth * ScreenWidth a partir daqui, como evito o Efeito de Peixe? demorei imenso chegar aqui... ao menos aprendi mas usei pixel a pixel e não o triangulo para percorrer a linha... sim é mais lento.... mas agora quero corrigir o Efeito de Peixe -
Visual Basic Raycasting: como calcular o tamanho da linha vertical?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
eis o código todo mesmo... não esquecer de mudar o nome do ficheiro no form_load(). Public Function BresenhamLine(X0 As Long, Y0 As Long, X1 As Long, Y1 As Long, ByRef Map() As Long, ObjectSize As Long, angle_rad As Double) As Long Dim dx As Long Dim dy As Long Dim steps As Double Dim Xincrement As Double Dim Yincrement As Double Dim x As Double Dim y As Double Dim MapX As Integer Dim MapY As Integer Dim LineWidth As Long x = X0 y = Y0 dx = X1 - X0 dy = Y1 - Y0 LineWidth = 0 If (Abs(dx) > Abs(dy)) Then steps = Abs(dx) Else steps = Abs(dy) End If Xincrement = dx / (steps) Yincrement = dy / (steps) Dim v As Integer For v = 0 To steps x = x + Xincrement y = y + Yincrement MapX = Int(x / ObjectSize) MapY = Int(y / ObjectSize) LineWidth = LineWidth + 1 If (Map(MapY, MapX) = vbBlue) Then Exit For End If Next v ForeColor vbRed DrawLine X0, Y0, Int(x), Int(y) LineWidth = LineWidth / Cos(angle_rad) BresenhamLine = LineWidth End Function Public Function DrawLineWithAngleAndLength(X1 As Long, Y1 As Long, angle_rad As Double, Length As Long, Map() As Long, ObjectSize As Long) As Long ' Calcular as coordenadas finais da linha Dim X2 As Long Dim Y2 As Long X2 = X1 + Length * Cos(angle_rad) Y2 = Y1 + Length * Sin(angle_rad) ' Chame a função BresenhamLine com as coordenadas finais DrawLineWithAngleAndLength = BresenhamLine(X1, Y1, X2, Y2, Map(), ObjectSize, angle_rad) End Function Private Sub DrawRays(StartRadians As Double, EndRadians As Double, VisionRadians As Double, ScreenWidth As Long, Optional Precision As Long = 1) Dim RayCount As Long Dim RaySteps As Double Dim RayWay As Long Dim RayWidth As Long Dim RayAngle As Double Dim RayHeight As Double 'number of rays: RayCount = ScreenWidth / CLng(VisionRadians) * Precision 'getting increment ray: RaySteps = (EndRadians - StartRadians) / CDbl(RayCount) Do While (RayWay < RayCount) 'calcule the ray angle\radians: RayAngle = StartRadians + (RaySteps * RayWay) 'draw ray and get ray width: RayWidth = A.DrawLineWithAngleAndLength(Int(Player.PosX), Int(Player.PosY), RayAngle, 300, LevelMap0(), 33) RayHeight = 66 / RayWidth * ScreenWidth / 2 'Debug.Print RayHeight A.ForeColor vbBlue A.DrawLine 475 + 50 + RayWay, 200 / 2 - RayHeight / 2, 475 + 50 + RayWay, 200 / 2 + RayHeight / 2 RayWay = RayWay + 1 Loop End Sub RayCasting3.7z -
Visual Basic Raycasting: como calcular o tamanho da linha vertical?
Cambalinho postou um tópico em Programação - outros
ao desenhar o raio, obtenho o comprimento do raio... ao saber o comprimento do raio, como calculo a altura da linha? como posso evitar o efeito de peixe? Dim RayAngle As Double Do While (RayWay < RayCount) RayAngle = StartRadians + (RaySteps * RayWay) RayWidth = A.DrawLineWithAngleAndLength(Int(Player.PosX), Int(Player.PosY), RayAngle, 300, LevelMap0(), 33) lineHeight = 200 / RayWidth * 2 drawStart = -lineHeight / 2 + 200 / 2 If drawStart < 0 Then drawStart = 0 drawEnd = lineHeight / 2 + 200 / 2 If drawEnd >= 200 Then drawEnd = 200 - 1 Me.Line (A.Width + RayWay, drawStart)-(A.Width + RayWay, drawEnd), vbWhite RayWay = RayWay + 1 Loop -
no windows 10, temos alguma configuração para mostrar a 1ª página de algum documento(doc, pdf, imagens), mas sem alterar o 'abrir'?
-
Visual Basic VB6: como desenhar 1 linha usando o método BresenhamLine, angulo e comprimento?
Cambalinho postou um tópico em Programação - outros
como desenhar 1 linha usando o método BresenhamLine, angulo e comprimento maximo e o mapa para 3D(RayCasting)? Public Sub BresenhamLine(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long, ByRef Map() As Long, ObjectSize As Long) Dim dx As Long Dim dy As Long Dim stepX As Long Dim stepY As Long Dim p As Long Dim MapX As Long Dim MapY As Long Dim x As Long Dim y As Long dx = Abs(X2 - X1) dy = Abs(Y2 - Y1) If X1 < X2 Then stepX = 1 Else stepX = -1 End If If Y1 < Y2 Then stepY = 1 Else stepY = -1 End If x = X1 y = Y1 'If (Map(Fix(x / ObjectSize), Fix(y / ObjectSize)) = 1) Then End Sub If dx > dy Then p = 2 * dy - dx Do While x <> X2 If p >= 0 Then y = y + stepY p = p - 2 * dx End If x = x + stepX p = p + 2 * dy If (Map(Int(x / ObjectSize), Int(y / ObjectSize)) = 1) Then ForeColor vbBlack DrawLine X1, Y1, X2, Y2 Exit Sub End If Loop Else p = 2 * dx - dy Do While y <> Y2 If p >= 0 Then x = x + stepX p = p - 2 * dy End If y = y + stepY p = p + 2 * dx If (Map(Int(x / ObjectSize), Int(y / ObjectSize)) = 1) Then ForeColor vbBlack DrawLine X1, Y1, X2, Y2 Exit Sub End If Loop End If DrawLine X1, Y1, X2, Y2 End Sub Public Sub DrawLineWithAngleAndLength(X1 As Long, Y1 As Long, angle_deg As Double, Length As Long, ByRef Map() As Long, ObjectSize As Long) ' Converter o ângulo para radianos Dim angle_rad As Double angle_rad = angle_deg '* 3.14159 / 180... sim já uso Radianos ' Calcular as coordenadas finais da linha Dim X2 As Long Dim Y2 As Long X2 = X1 + Length * Cos(angle_rad) Y2 = Y1 + Length * Sin(angle_rad) ' Chame a função BresenhamLine com as coordenadas finais BresenhamLine X1, Y1, X2, Y2, Map, ObjectSize End Sub estou a obter resultados inesperados no if: If (Map(Int(x / ObjectSize), Int(y / ObjectSize)) = 1) Then ForeColor vbBlack DrawLine X1, Y1, X2, Y2 Exit Sub End If até posso obter '-1'... mas não faz sentido... porque o Zero do array Map() é 1... por isso não me deveria dar esse erro-
- 1
-
-
Visual Basic VB6 - Classes: posso evitar set e new para inicializar a classe?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
ok.. muito obrigado -
Visual Basic VB6 - Classes: posso evitar set e new para inicializar a classe?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
muito obrigado pela correção. me corrija mais um pouco: - mesmo que a classe esteja numa libraria tenho de usar sempre o 'new'? - com o 'new' é possível chamar 1 função\método? sim, chama o initializate()... mas posso usar parametros? -
Visual Basic VB6 - Classes: posso evitar set e new para inicializar a classe?
Cambalinho postou um tópico em Programação - outros
dim s as newclasse set s = new newclasse sempre que crio 1 instancia da classe tenho de fazer essa segunda linha.... é possível evitar essa segunda linha? é possível 'meter' essa linha na classe? -
Visual Basic VB6 - como usar o CopyMemory()?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
e consegui: Public ptr As Long Public Sub GetPointer(ByRef valor As Variant) 'Debug.Print TypeName(valor) If (TypeName(valor) = "Long") Then ptr = VarPtr(valor) ElseIf (TypeName(valor) = "String") Then ptr = StrPtr(valor) End If End Sub Public Sub SetValue(value As Variant) If (ptr = 0) Then Exit Sub If (TypeName(value) = "Long") Then Call CopyMemory(ByVal ptr, value, Len(value)) ElseIf (TypeName(value) = "String") Then CopyMemory ByVal (ptr), ByVal StrPtr(value), LenB(value) End If End Sub mas ainda me falta corrigir este código: Private Declare Sub GetDWord Lib "MSVBVM60.dll" Alias _ "GetMem4" (ByRef inSrc As Any, ByRef inDst As Any) Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) 'Gets the address variable value: Private Function DeRef(ByVal inPtr As Long) As Long If (inPtr) Then Call GetDWord(ByVal inPtr, DeRef) End Function Public Function GetValueAddressed() As Long If (ptr = 0) Then Exit Function GetValueAddressed = DeRef(ptr) End Function ainda não percebi como posso alterar estas funções para usar String -
Visual Basic VB6 - como usar o CopyMemory()?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
agora o string funciona: Option Explicit Private Declare Sub GetDWord Lib "MSVBVM60.dll" Alias _ "GetMem4" (ByRef inSrc As Any, ByRef inDst As Long) Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Public ptr As Long 'Gets the address variable value: Private Function DeRef(ByVal inPtr As Long) As Long If (inPtr) Then Call GetDWord(ByVal inPtr, DeRef) End Function Public Sub GetPointer(ByRef valor As Long) ptr = VarPtr(valor) End Sub Public Sub GetPointerString(ByRef valor As String) ptr = StrPtr(valor) End Sub Public Function GetValueAddressed() As Long If (ptr = 0) Then Exit Function GetValueAddressed = DeRef(ptr) End Function Public Sub SetValue(value As Long) If (ptr = 0) Then Exit Sub Call CopyMemory(ByVal ptr, value, Len(value)) End Sub Public Sub SetStringValue(value As String) If (ptr = 0) Then Exit Sub CopyMemory ByVal (ptr), ByVal StrPtr(value), LenB(value) End Sub Public Function GetAddressed() As Long If (ptr = 0) Then GetAddressed = 0 GetAddressed = Hex(ptr) 'hex for get the hexadecimal values: memory addresses End Function com uso(sempre me esqueço do 'set nomevaraivel = new tipo' kkkk) Private Sub Form_Load() Dim MyVar As String Dim ptr As Pointer Set ptr = New Pointer MyVar = "joaquim Miguel Cambarinho de Jesus" ptr.GetPointerString MyVar ptr.SetStringValue "hello world" Debug.Print MyVar End Sub resultado: "hello worlduel Cambarinho de Jesus" o que não sei: 1 - é possível juntar a função GetPointer() e GetPointerString() numa? e será que posso usar double e float? 2 - ainda não sei usar os arrays... se tiver algumas dicas, por favor diga -
Visual Basic VB6 - como usar o CopyMemory()?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
muito obrigado pela correção. agora preciso de atualizar: posso usar o tipo 'variant' ou isso? estou a testar isto: Private Sub Form_Load() Dim MyVar As Long Dim name As String Dim s As String name = "joaquim" MyVar = VarPtr(name) s = "joao" CopyMemory ByVal (MyVar), s, LenB(s) Debug.Print name End Sub o resultado é: '??' e nem sei o motivo -
Visual Basic VB6 - como usar o CopyMemory()?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
até testei, mas a linha fica vermelha.... e isso é erro.. testei agora mesmo... é sério: devido a ser assim que funciona.. .digo eu.. posso usar o tipo 'variant' ou 'object' para aceitar qualquer tipo de dados? -
Visual Basic VB6 - como usar o CopyMemory()?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
resolvido: Private Sub Form_Load() Dim MyVar As Long, MyPtr As Long MyVar = 12345 ' Set a variable value MyPtr = VarPtr(MyVar) ' Get a pointer to variable Debug.Print DeRef(MyPtr) ' De-reference - Prints "12345": prints the address variable value Dim MyVar2 As Long MyVar2 = 2000 'copy the '24' value to address variable: Call CopyMemory(ByVal MyPtr, MyVar2, Len(MyVar2)) Debug.Print MyVar End Sub 1 - VarPtr() obtém o endereço da variável; 2 - DefRef() obtém o valor da variável endereçada; 3 - CopyMemory(ByVal PonteiroDestino, ValorOrigem, TamanhoOrigem)... ... sim 'ByVal' fez a diferença... declaração: Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) o meu código usa Long, como posso fazer para aceitar outros tipos? acabei de atualizar a class: Option Explicit Private Declare Sub GetDWord Lib "MSVBVM60.dll" Alias _ "GetMem4" (ByRef inSrc As Any, ByRef inDst As Long) Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Private ptr As Long 'Gets the address variable value: Private Function DeRef(ByVal inPtr As Long) As Long If (inPtr) Then Call GetDWord(ByVal inPtr, DeRef) End Function Public Sub GetPointer(ByRef valor As Long) 'permite aceitar o sinal de igual ptr = VarPtr(valor) End Sub Public Function GetValueAddressed() As Long GetValueAddressed = DeRef(ptr) End Function Public Sub SetValue(value As Long) Call CopyMemory(ByVal ptr, value, Len(value)) End Sub Public Function GetAddressed() As Variant GetAddressed = Hex(ptr) 'hex for get the hexadecimal values: memory addresses End Function 'como a uso: Private Sub Form_Load() Dim MyVar As Long Dim ptr As Pointer Set ptr = New Pointer MyVar = 30 ptr.GetPointer MyVar ptr.SetValue 2000 Debug.Print MyVar End Sub 'imprimido: '2000' e está correto.... o problema é que só aceita long -
Visual Basic VB6 - como usar o CopyMemory()?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
o varptr() é para obter o endereço da variavel o MyPtr recebe o ponteiro.. agora como posso usar o 'MyPtr ' na CopyMemory() para alterar o valor na 'MyVar'? Call CopyMemory(MyPtr, 12, Len(MyPtr)) o 'MyPtr' tem o endereço da variável... como faço para CopyMemory() usar isso? -
Visual Basic VB6 - como usar o CopyMemory()?
Cambalinho respondeu ao tópico de Cambalinho em Programação - outros
o problema é que o 'MyPtr' é 1 ponteiro... e este é que altera o valor de 'MyVar'... e sim usei 1 valor literal para testar... então se o 'MyPtr' já tem endereço de memória do 'MyVar', como posso alterar o valor do 'MyVar' usando o 'MyPtr'? -
eis a declaração do CopyMemory() no VB6: Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) a minha questão é: como se usa o CopyMemory() corretamente? eu já tentei usar, mas sem sorte: Option Explicit Private Declare Sub GetDWord Lib "MSVBVM60.dll" Alias _ "GetMem4" (ByRef inSrc As Any, ByRef inDst As Long) Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) 'Gets the address variable value: Private Function DeRef(ByVal inPtr As Long) As Long If (inPtr) Then Call GetDWord(ByVal inPtr, DeRef) End Function Private Sub Form_Load() Dim MyVar As Long, MyPtr As Long MyVar = 12345 ' Set a variable value MyPtr = VarPtr(MyVar) ' Get a pointer to variable Debug.Print DeRef(MyPtr) ' De-reference - Prints "12345": prints the address variable value 'copy the '24' value to address variable: Call CopyMemory(DeRef(MyPtr), 24, Len(MyVar)) Debug.Print DeRef(MyPtr) End Sub o 'DeRef() é para obter o valor da variável endereçada; o VarPtr() é para obter o endereço da variável. o meu objetivo, agora, é criar 1 classe Ponteiros para usar em VB6. assim posso obter, por exemplo, 1 array de pixels do CreateBitmap() ou CreateDIBSection(). o CopyMemory() ajuda muito, mas ainda estou confuso a usar com variáveis, quanto mais com ponteiros e arrays.
-
como desativar o Read-Only num cartão SD?
Cambalinho respondeu ao tópico de Cambalinho em Pen drives e cartões de memória
parece que resolvi: 1 - usei 1 leitor de cartões em vez do adaptador; 2 - usei 1 programa para o formatar; 3 - usei o DiskPart para limpar os atributos e vi que estavam corretos; 4 - mesmo com o adaptador posso apagar os ficheiros e pastas... 5 - porque o Windows não deixa formatar? -
como desativar o Read-Only num cartão SD?
Cambalinho respondeu ao tópico de Cambalinho em Pen drives e cartões de memória
essa trava está para cima, para baixo fica 'lock'.. testei 1 pen USB, Leitora de Cartões, e formatei com 1 programa... o Windows 10 não consegue formatar na mesma. tenho 1 erro no próprio cartão e talvez no adaptador, mas não sei resolver -
como desativar o Read-Only num cartão SD?
Cambalinho postou um tópico em Pen drives e cartões de memória
no adaptador do microsd, tenho 1 botão que está para cima... e isso permite fazer leitura e escrita... mas tenho 1 erro no cartão de memória: não posso apagar ou formatar, porque dá-me 1 erro de erro 'read-only'... eu já tentei usar o DiskPart do CMD sem sucesso -
Visual Basic VB6: como melhorar o desempenho do ciclo 'for'?
Cambalinho postou um tópico em Programação - outros
eu sei que é 1 linguagem antiga... mesmo assim vamos falar sobre desempenho nos ciclos: Public Function SetTransparentColor(color As Long) Dim X As Integer Dim Y As Integer Dim c As Long Dim h As Long Dim w As Long Dim temp As BGRAQUAD ' substitua BGRColor pelo tipo de dado correto usado em bDibBGRA h = Height - 1 w = Width - 1 For c = 0 To h * w ' movendo as operações fora do loop for X = c Mod (w + 1) Y = Int(c / (w + 1)) temp = bDibBGRA(c) ' modificando apenas a propriedade necessária If (RGB(temp.B, temp.G, temp.R) = color) Then temp.B = 255 bDibBGRA(c) = temp End If Next c End Function esta função, mesmo sem nada dentro do 'for', consome imenso desempenho... porque isso acontece? deveria usar 'while' ou tem haver com outras coisas?-
- 1
-
-
C++ Como usar __attribute__((weak)) para testar se a função foi definida?
Cambalinho respondeu ao tópico de Cambalinho em C/C#/C++
eu percebi mal alguma coisa.. desculpe: #include <iostream> using namespace std; class test2 { public: void (*Hello)(); void hey() { if (this->Hello != NULL) this->Hello(); } }; void test2::Hello() { cout << "hello"; } int main() { test2::Hello(); cin.get(); return 0; } tenho 1 erro na linha: void test2::Hello() "error: cannot declare pointer to 'void' member" -
C++ Como usar __attribute__((weak)) para testar se a função foi definida?
Cambalinho respondeu ao tópico de Cambalinho em C/C#/C++
muito obrigado a todos... então fico com a questão: sei que posso usar variáveis de funções... mas é(é o meu objetivo principal) possível testar se a função foi definida ou não?
Sobre o Clube do Hardware
No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais
Direitos autorais
Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais