Solved

Porting MS C to MS Visual C

Posted on 1998-09-23
8
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

691 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