Lock cursor on the center of screen

i have tried many options with Screen.lockCursor = true; etc

so i was told its possible to use a dll file to lock the cursor in the middle of the screen system.windows.forms.dll is the one im told to use but i dont know how i would start to get it to work or what code i would use in c# to make the cursor center ,

the problem is that i put Screen.lockCursor = true; in code but when i do it OnMouseOver doesnt work or similar things like OnMouseEnter. it works perfectly fine without the lockcursor but with it the on mouse stuff doesnt work

i have tried running the game to see if its just a problem with the in house play .

things i have tried :
Screen.lockCursor = true;
Screen.lockCursor = false; (in the update)

if(Screen.lockCursor == false)
Screen.lockCursor = true; (update also)

either need to fix the problem with lock cursor or use the dll method but i need to be told how to set it up,
thanks for any help in advance!

what I use so u can unlock it in mid game so u can be able to exit out (sorry its in java, u can allways make a new script)

// lock at beggining
function Start ()
{
Screen.lockCursor = true;
}
//unlock in mid game

function Update()
{
Screen.showCursor = false;
   
    if (Input.GetKeyDown(KeyCode.P))
    	if (Screen.lockCursor)
    	Screen.lockCursor = false;
    	
    else{
    Screen.lockCursor = true;
}

}

im not exactly sure about how the coding would go but you could try to add a gui texture to the middle of the screen and try and raycast from that if possible. basically replace the curser with that.

with what you said there about needing the cursor for barricades and shops, cant you just make a BoxCollider and set it to trigger, and make it a realistic distance?