我在Win32控制台应用程序中有2个文件,A.cpp和B.cpp.
这2个文件只包含以下2行代码:
#include "stdafx.h"
int k;
Run Code Online (Sandbox Code Playgroud)
编译时会产生错误
Error 1 error LNK2005: "int k" (?a@@3HA) already defined in A.obj
Run Code Online (Sandbox Code Playgroud)
我不明白发生了什么.
有人可以向我解释一下吗?
我在C#上使用WPF代码如下
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:utility="clr-namespace:DVRClientInterface.Utility"
xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:wpftoolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
xmlns:customControl="clr-namespace:DVRClientInterface.CustomControls"
x:Class="DVRClientInterface.MainWindow"
WindowStyle="None" ResizeMode="CanMinimize"
AllowsTransparency="True"
WindowState = "Maximized"
WindowStartupLocation="CenterScreen"
StateChanged="Window_StateChanged"
KeyUp="Window_KeyUp"
KeyDown="Window_KeyDown"
Closing="Window_Closing" Loaded="Window_Loaded"
>
<!-- WindowState = "Maximized" -->
<Window.Background>
<ImageBrush ImageSource="Resources\main_background.png"/>
</Window.Background>
<Grid x:Name="MainWindowGrid">
//My GUI Code here
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,它将抛出以下异常
An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'The invocation of the constructor on type 'DVRClientInterface.MainWindow' that matches the specified binding constraints threw an exception.' Line number '9' and line position '5'.
If there …Run Code Online (Sandbox Code Playgroud) 我想从IntPtr指针获取数据到字节数组.我可以使用以下代码来执行此操作:
IntPtr intPtr = GetBuff();
byte[] b = new byte[length];
Marshal.Copy(intPtr, b, 0, length);
Run Code Online (Sandbox Code Playgroud)
但是上面的代码强制从IntPtr到字节数组的复制操作.当有问题的数据很大时,这不是一个好的解决方案.
有没有办法将IntPtr转换为字节数组?例如,以下工作:
byte[] b = (byte[])intPtr
这将消除复制操作的需要.
另外:我们如何确定IntPtr指向的数据长度?
我正在使用WPF(C#)的进度条来描述进程的进度.
我的算法如下:
DoSomethingCode1();
ProgressBar.SetPercent(10); // 10%
DoSomethingCode2();
ProgressBar.SetPercent(20); // 20%
...
DoSomethingCode10();
ProgressBar.SetPercent(100); // 100%
Run Code Online (Sandbox Code Playgroud)
没关系,但它会使进度条不连续.
有人可以告诉我一些让进度条轻柔更新的建议吗?
我想使用c ++代码从位图图像制作.avi视频文件.我写了以下代码:
//Get RGB array data from bmp file
uint8_t* rgb24Data = new uint8_t[3*imgWidth*imgHeight];
hBitmap = (HBITMAP) LoadImage( NULL, _T("myfile.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
GetDIBits(hdc, hBitmap, 0, imgHeight, rgb24Data , (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
/* Allocate the encoded raw picture. */
AVPicture dst_picture;
avpicture_alloc(&dst_picture, AV_PIX_FMT_YUV420P, imgWidth, imgHeight);
/* Convert rgb24Data to YUV420p and stored into array dst_picture.data */
RGB24toYUV420P(imgWidth, imgHeight, rgb24Data, dst_picture.data); //How to implement this function?
//code for encode frame dst_picture here
Run Code Online (Sandbox Code Playgroud)
我的问题是如何实现RGB24toYUV420P()函数,这个函数会将RGB24数据从数组rgb24Data 转换为YUV420p存储到dst_picture.data …
我正在使用VisualTreeHelper.GetChildrenCount()查找子控件,但它总是返回0.
这是我的代码
<ScrollViewer x:Name="scrollViewerChannelsRecordTimeData">
<StackPanel x:Name="channelsRecordTimeData">
<ItemsControl x:Name="channelRecordTimeItems" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid x:Name="hoursLines">
//Some Controls here
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
C#代码:
channelRecordTimeItems.ItemContainerGenerator.StatusChanged += ChannelRecordTimeItemsStatusChangedEventHandler;
private void ChannelRecordTimeItemsStatusChangedEventHandler(Object sender, EventArgs e)
{
if (channelRecordTimeItems.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
{
if (channelRecordTimeItems.HasItems)
{
DependencyObject dependencyObject = null;
Grid gridHighlightRecordData = null;
for (int i = 0; i < channelRecordTimeItems.Items.Count; i++)
{
dependencyObject = channelRecordTimeItems.ItemContainerGenerator.ContainerFromIndex(i); //dependencyObject != null
if (dependencyObject != null)
{
Grid hoursLines = FindElement.FindChild<Grid>(dependencyObject, "hoursLines"); //hoursLines = null …Run Code Online (Sandbox Code Playgroud) 我在C#上使用wpf来设计GUI,我想从xaml代码中获取屏幕大小(宽度和高度的值).
我知道如何从C#代码中获取它们
Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
Run Code Online (Sandbox Code Playgroud)
但我不知道如何从XAML代码中获取它们.
我使用WPF,我感到困惑的执行顺序Control.Dispatcher.BeginInvoke()和Control.Dispatcher.Invoke().
我将在下面展示一个代码示例
backgroundThread = new Thread(BackgroundThread);
backgroundThread.Start();
public void BackgroundThread()
{
this.Dispatcher.BeginInvoke(new Action(delegate()
{
WriteLog("Run command 1");
}));
this.Dispatcher.Invoke(new Action(delegate()
{
WriteLog("Run command 2");
}));
}
Run Code Online (Sandbox Code Playgroud)
我希望"命令1"将在"命令2"之前运行并完成,但有时似乎"命令2"在"命令1"之前运行.我对互联网和MSDN文档进行了很多研究,但我不明白为什么会这样.
有人请告诉我这些功能的规则究竟是什么?
非常感谢!
T&T
我正在使用 DirectX 来绘制视频。通过Intel Media SDK解码后。然后我通过以下英特尔代码绘制它:
mfxStatus CD3D11Device::RenderFrame(mfxFrameSurface1 * pSrf, mfxFrameAllocator * pAlloc)
{
HRESULT hres = S_OK;
mfxStatus sts;
sts = CreateVideoProcessor(pSrf);
MSDK_CHECK_STATUS(sts, "CreateVideoProcessor failed");
hres = m_pSwapChain->GetBuffer(0, __uuidof( ID3D11Texture2D ), (void**)&m_pDXGIBackBuffer.p);
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC OutputViewDesc;
if (2 == m_nViews)
{
m_pVideoContext->VideoProcessorSetStreamStereoFormat(m_pVideoProcessor, 0, TRUE,D3D11_VIDEO_PROCESSOR_STEREO_FORMAT_SEPARATE,
TRUE, TRUE, D3D11_VIDEO_PROCESSOR_STEREO_FLIP_NONE, NULL);
m_pVideoContext->VideoProcessorSetOutputStereoMode(m_pVideoProcessor,TRUE);
OutputViewDesc.ViewDimension = D3D11_VPOV_DIMENSION_TEXTURE2DARRAY;
OutputViewDesc.Texture2DArray.ArraySize = 2;
OutputViewDesc.Texture2DArray.MipSlice = 0;
OutputViewDesc.Texture2DArray.FirstArraySlice = 0;
}
else
{
OutputViewDesc.ViewDimension = D3D11_VPOV_DIMENSION_TEXTURE2D;
OutputViewDesc.Texture2D.MipSlice = 0;
}
if (1 == m_nViews || 0 == …Run Code Online (Sandbox Code Playgroud) 我想使用 dllexport 导出函数。但是我在编译器“错误 C4439:'WrappedC':签名中具有托管类型的函数定义必须具有 __clrcall 调用约定”时遇到了错误。
我在头文件(.h)中的代码是:
extern "C"
{
__declspec(dllexport) int __stdcall ABC(int i);
__declspec(dllexport) char* __stdcall C(int i);
__declspec(dllexport) array<char>^ __stdcall WrappedC(int i) ;
}
Run Code Online (Sandbox Code Playgroud)
我尝试将 _stdcall 更改为 __clrcall 但又出现另一个错误:
error C3395: 'WrappedC' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention
Run Code Online (Sandbox Code Playgroud)
我在网上搜索过,但还没有解决。
谢谢,
大统华集团
c# ×6
wpf ×5
c++ ×3
.net ×2
rgb ×2
yuv ×2
directx-11 ×1
dllexport ×1
ffmpeg ×1
intptr ×1
managed-c++ ×1
progress-bar ×1
texture2d ×1