Solved

Porting MS C to MS Visual C

Posted on 1998-09-23
8
282 Views
Last Modified: 2010-04-15
Hi!!!
I have my source code in MS C. Now I need use VC
    My Source code compile OK (only 1 warning), but Link  and received the following:

    Timer.obj : error LNK2001: unresolved external symbol _IntSvcRtn
    Timer.obj : error LNK2001: unresolved external symbol _wCount
    .........
    .... another

    IntSvcRtn function is under a  .asm source code file, I use
    #pragma alloc_text(FIXED_TEXT,IntSvcRtn) function C

    Source code .asm file is:
    ....
    FIXED_DATA SEGMENT DWORD PUBLIC 'DATA'
    ....
    ....
    FIXED_TEXT SEGMENT PARA PUBLIC 'CODE'
    selData1    dw FIXED_DATA
    assume CS:FIXED_TEXT,DS:NOTHING
    PUBLIC _IntSvcRtn
    _IntSvcRtn label far
     IntSvcRtn proc far
    sub sp,4
            ....
            ....

    What's Up??
    I need Porting my MS C code (32bits) to MS Visual C 5.0 (32bits).

    What I can do?? any Idea??  

    Thanks Again!!
    Sincerely.
0
Comment
Question by:hpv75
  • 5
  • 3
8 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 20 total points
ID: 1252992
The easiest way usually would be to use an inline assembler sequence, as MASM is not a part of VC++ - but as 'sub sp,4' uses a 16 bit register, i assume you'll run into difficulties... anyway (check & alter return type and parameters!):

// to prevent the compiler from
// generating stack frames
__declspec ( naked) void IntSvcRtn ( void)
{
 __asm {
         sub sp,4
         .....
       };
}

0
 

Author Comment

by:hpv75
ID: 1252993
Thanks Again!!! jrk!
0
 
LVL 86

Expert Comment

by:jkr
ID: 1252994
So - does it compile _and_ work? ;-)
0
 

Author Comment

by:hpv75
ID: 1252995
Thanks Again friend jkr
.. but what`s ups with my source code asm..  I don´t know  

how porting this code to inline asm?? i don`t know ,by sample what`s up in FIXED_TEXT
.another......
I use in C , #pragma alloc_text(FIXED_TEXT,IntSvcRtn)  (IntSvcRtn in asm assembly
source code)

PLEASE HELPME!!

THANKS AGAIN!!! jkr !

Sincelery!!!


it is my asm, source code!


page ,132

; masm tisr ; >err
      .286p
xlist
include dpmi.h
include pic.h
list

TIMER_IRQ EQU 0

WM_COMMAND          = 0111h

EXTRN POSTMESSAGE:FAR

Words struc
LoWord dw ?
HiWord dw ?
Words ends
;
; Set variables for our interrupt number
;
INT_DEV equ (INT_MASTER_0+(TIMER_IRQ AND 7))
PIC00 equ INTA00
PIC01 equ INTA01
page

PUBLIC _hWndEvent,_wParamEvent,_wCount,_lpfnPrevISR
_hWndEvent label word
hWndEvent dw  0             ; Window to post events to

_wParamEvent label word
wParamEvent dw      0            ; wParam value to post

_wCount label word
wCount dw  0                  ; count of unprocessed interrupts

_lpfnPrevISR label dword      ; address of previous ISR
lpfnPrevISR dd 0

FIXED_DATA ENDS

page

;IP      IntSvcRtn - The Interrupt Service Routine

FIXED_TEXT SEGMENT PARA PUBLIC 'CODE'
selData1    dw      FIXED_DATA
      assume      CS:FIXED_TEXT,DS:NOTHING
PUBLIC _IntSvcRtn
_IntSvcRtn label far
IntSvcRtn proc far
      sub      sp,4                ; save space for return address
      push      bp
      mov      bp,sp
      push      ax
      push      dx
      push      ds
      mov      ds,selData1
      assume      ds:FIXED_DATA
      inc      wCount

      mov      ax,lpfnPrevISR.LoWord      ; store return address
      mov      [bp+2],ax
      mov      ax,lpfnPrevISR.HiWord
      mov      [bp+4],ax

      cmp      hWndEvent,0          ; exiting?
      jz      isr9                ; if so, then don't restart or post
      cmp      wCount,1          ; Need to post?
      jne      isr9                ; skip if not

      push      bx                ; save the remaining registers
      push      cx
      push      es

      push      hWndEvent
      push      WM_COMMAND
      push      wParamEvent
      push      0      ; lParam is zero
      push      0
      call      POSTMESSAGE          ; post the event

      pop      es
      pop      cx
      pop      bx

isr9:
      pop      ds
      assume      ds:NOTHING
      pop      dx
      pop      ax
      leave
      retf
IntSvcRtn endp

FIXED_TEXT ENDS
      end

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 86

Expert Comment

by:jkr
ID: 1252996
Well, the first problem: this is 16bit assembler - you'll have to port it to 32bit assembler first before using it with VC++.
Usually, converting code to inline assembler is no problem, e.g.

386
model flat

extrn _CCommonReturnPoint:proc

code

public _AsmCommonReturnPoint

_AsmCommonReturnPoint proc
    SUB     ESP,4   ; Make space for return address
    PUSHAD
    MOV     EAX,ESP
    PUSH    EAX
    CALL    _CCommonReturnPoint
    ADD     ESP,4
    POPAD
    RET
_AsmCommonReturnPoint endp

END

will be

__declspec ( naked)
void AsmCommonReturnPoint( void)
{
__asm{
    SUB     ESP,4   ; Make space for return address
    PUSHAD
    MOV     EAX,ESP
    PUSH    EAX
    CALL    CCommonReturnPoint
    ADD     ESP,4
    POPAD
    RET
    }
}
afterwards.

Second problem:
If i understood the .asm code right it is an interrupt service routine - somthing that can only be done in a kernel mode driver on a Win32 platform.... (BTW: There's an error in your assembler code - after resetting DS and clearing the stack frame the routine returns with a 'retf', but as it is an ISR, it should read 'reti')
0
 

Author Comment

by:hpv75
ID: 1252997
Thanks Again JKR!!

 Now ... I use __asm instructions... But I have Error messages:


 errror c2095: 'SetPMVector' : actual parameter has type void' : parameter 2
 error C2198: 'SetPMVector' : too few actual parameters
 Error executing cl.exe.

 Whats Ups? Please Help Me jkr !
 Thanks Again!!

My Source Code Is:
..
..
void SetPMVector(int iVector, FARPROC lpfnISR)
{
    _asm {
      push      ds
      lds      dx,lpfnISR
      mov      al,byte ptr iVector
      mov      ah,25h
      int      21h            
      pop      ds
      }
}

void __declspec (dllexport) FAR PASCAL TimerStart(HWND hWnd, WPARAM wParam){
    wParamEvent= wParam ;
    hWndEvent= hWnd ;
    if(!lpfnPrevISR){
      __asm cli
      lpfnPrevISR = GetPMVector(INT_DEV) ;      
      SetPMVector(INT_DEV , IntSvcRtn()); //  <== error Message !!!! What`s Up?
      __asm sti
      }
}
....
....
0
 
LVL 86

Expert Comment

by:jkr
ID: 1252998
Try

SetPMVector(INT_DEV , IntSvcRtn);

'SetPMVector(INT_DEV , IntSvcRtn());' will use the _return value_ of 'IntSvcRtn()' as the parameter for 'SetPMVector()'...
0
 
LVL 86

Expert Comment

by:jkr
ID: 1252999
Now, hpv75 - do you accept my answer???
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Pointer in one class to member in another 6 112
Adjust Mfcapp 29 155
negation in C function 14 132
Socket Programming (Unix) 8 102
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now