Recent Posts

Pages: [1] 2 3 ... 10
2
The Campus / Re: trouble with external variables
« Last post by TWell on July 28, 2017, 05:46:12 PM »
An another example:
Code: [Select]
.386
.model flat, stdcall
option casemap :none

includelib msvcrt
printf proto C :ptr byte, :vararg
exit proto C :dword

includelib MyDll1
extern _imp__MyNum :dword

.data
fmt db "%p",10,0
MyNum1 dd ?

.code
mainCRTStartup proc C
mov eax, _imp__MyNum
mov eax, dword ptr[eax]
mov MyNum1, eax
invoke printf,addr fmt, MyNum1
invoke exit,0
mainCRTStartup endp
end
Code: [Select]
00000005
3
The Campus / Re: trouble with external variables
« Last post by aw27 on July 28, 2017, 04:33:09 PM »
In DLL:
extern "C" const int MyNum = 5;
In .DEF
LIBRARY   MYDLL
EXPORTS 
  MyNum = MyNum CONSTANT

In MASM:
Code: [Select]
.686
.model Flat, STDCALL
option Casemap :None

includelib \masm32\lib\msvcrt.lib
printf proto C :ptr, :vararg
includelib mydll.lib
externdef MyNum : sdword

.data

format db 'MyNum is %d', 13,10,0

.code

start1 proc public
mov edx, MyNum
mov edx, [edx]
INVOKE printf, addr format, edx
ret
start1 endp

main proc C public
invoke start1
ret

main endp
end

Tested and works.
4
The Campus / Re: trouble with external variables
« Last post by hutch-- on July 28, 2017, 01:04:03 PM »
I don't know if C++ decorates the external function name but I would try STDCALL as the calling convention.
5
The Campus / trouble with external variables
« Last post by oinka720 on July 28, 2017, 12:50:19 PM »
Hi all.  This ought to be simple but I can't figure it out.  I have a test dll written in c++

Code: [Select]
// MyDLL.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"


extern "C" __declspec( dllexport ) public int MyNum = 5;

and then I have a test asm where I try to access the variable

Code: [Select]
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

;                 Build this with the "Project" menu using
;                       "Console Assemble and Link"

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .486                                    ; create 32 bit code
    .model flat, stdcall                    ; 32 bit memory model
    option casemap :none                    ; case sensitive
 
    include \masm32\include\windows.inc     ; always first
    include \masm32\macros\macros.asm       ; MASM support macros

  ; -----------------------------------------------------------------
  ; include files that have MASM format prototypes for function calls
  ; -----------------------------------------------------------------
    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\msvcrt.inc

  ; ------------------------------------------------
  ; Library files that have definitions for function
  ; exports and tested reliable prebuilt code.
  ; ------------------------------------------------
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\msvcrt.lib
   
   
    includelib mydll.lib

    .code                       ; Tell MASM where the code starts

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

start:                          ; The CODE entry point to the program

;mov MyNum, 5
 
    push MyNum
    push offset format
    call crt_printf
   
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««


.data

format db 'MyNum is %i', 13,10,0
extern MyNum:dword

end start                       ; Tell MASM where the program ends



it assembles and links, but ...

Problem1: it prints a random number rather than the expected 5.
Problem2: if I uncomment the line ;mov MyNum, 5 I get a runtime error "access violation"

Any assistance is appreciated.  Thanks.
6
The Soap Box / Re: A really good looking salt water crocodile.
« Last post by hutch-- on July 28, 2017, 12:10:14 PM »
Looks great, will have to find a viewable copy. My dad spent a lot of time in the northern part of West OZ and then the Northern Territory before ww2 and was familiar with very large salt water crocodiles before they were shot out by hunters and he said that the best way to stop one charging at you was a 12 gauge shotgun into their open mouth. Back then it was reasonably common to get old ones that were 20 feet long and over. Since they have been protected about 30 years ago they are now almost epidemic and are moving a long way up waterways so you are at risk being anywhere near their habitat.

Don't go swimming in the rivers up north at night time and mostly in the daylight either or you will end up as a crocodile's breakfast.
7
The Workshop / Re: Introduction + Silly Question :)
« Last post by hutch-- on July 28, 2017, 10:18:41 AM »
I have split this topic as I think Rob's original question has been answered and placed the following discussion in another thread so it is dealt with as discussion, not advice to the original poster.
8
The Workshop / Re: Discussion + Introduction + Silly Question :)
« Last post by raymond on July 28, 2017, 07:02:05 AM »
Quote
For Delphi, Free Pascal and other languages it is a snap
I have been told that Python is not able to use the 80-bit floats at all.
9
The Workshop / Re: Discussion + Introduction + Silly Question :)
« Last post by TWell on July 28, 2017, 06:33:45 AM »
one example is the use of extended double-precision floats (80-bit).
long double in gcc, icc ?
10
The Workshop / Re: Discussion + Introduction + Silly Question :)
« Last post by aw27 on July 28, 2017, 06:26:19 AM »
one example is the use of extended double-precision floats (80-bit).

Actually it is a problem of software that depends on the CRT library.
For Delphi, Free Pascal and other languages it is a snap.
http://www.delphibasics.co.uk/RTL.asp?Name=Extended

Pages: [1] 2 3 ... 10