• C

Porting MS C to MS Visual C

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.
hpv75Asked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
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
 
hpv75Author Commented:
Thanks Again!!! jrk!
0
 
jkrCommented:
So - does it compile _and_ work? ;-)
0
The Lifecycle Approach to Managing Security Policy

Managing application connectivity and security policies can be achieved more effectively when following a framework that automates repeatable processes and ensures that the right activities are performed in the right order.

 
hpv75Author Commented:
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
 
jkrCommented:
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
 
hpv75Author Commented:
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
 
jkrCommented:
Try

SetPMVector(INT_DEV , IntSvcRtn);

'SetPMVector(INT_DEV , IntSvcRtn());' will use the _return value_ of 'IntSvcRtn()' as the parameter for 'SetPMVector()'...
0
 
jkrCommented:
Now, hpv75 - do you accept my answer???
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.